[sword-svn] r1785 - in trunk: . include src/utilfuns tests
scribe at crosswire.org
scribe at crosswire.org
Sat Apr 30 12:11:13 MST 2005
Author: scribe
Date: 2005-04-30 12:11:12 -0700 (Sat, 30 Apr 2005)
New Revision: 1785
Modified:
trunk/include/swbuf.h
trunk/src/utilfuns/swbuf.cpp
trunk/tests/swbuftest.cpp
trunk/usrinst.sh
Log:
optimizations for swbuf
Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h 2005-04-30 01:57:10 UTC (rev 1784)
+++ trunk/include/swbuf.h 2005-04-30 19:11:12 UTC (rev 1785)
@@ -47,37 +47,51 @@
static char *nullStr;
static char junkBuf[JUNKBUFSIZE];
- inline void assureMore(signed long pastEnd) {
+ inline void assureMore(size_t pastEnd) {
if (endAlloc-end < pastEnd) {
- long newsize = (end-buf)+pastEnd;
- allocSize = newsize + 128;
- long size = (end - buf);
- buf = (char *)((buf) ? realloc(buf, allocSize) : malloc(allocSize));
- end = (buf + size);
- *end = 0;
- endAlloc = buf + allocSize-1;
+ assureSize(allocSize + pastEnd);
}
}
- inline void assureSize(unsigned long newsize) {
- if (newsize > allocSize) {
- allocSize = newsize + 128;
+
+ inline void assureSize(size_t checkSize) {
+ if (checkSize > allocSize) {
long size = (end - buf);
- buf = (char *)((buf) ? realloc(buf, allocSize) : malloc(allocSize));
+ checkSize += 128;
+ buf = (char *)((allocSize) ? realloc(buf, checkSize) : malloc(checkSize));
+ allocSize = checkSize;
end = (buf + size);
*end = 0;
- endAlloc = buf + allocSize-1;
+ endAlloc = buf + allocSize - 1;
}
}
- void init(unsigned long initSize);
+ inline void init(size_t initSize) {
+ fillByte = ' ';
+ allocSize = 0;
+ buf = nullStr;
+ end = buf;
+ endAlloc = buf;
+ if (initSize)
+ assureSize(initSize);
+ }
+
public:
+
+ /******************************************************************************
+ * SWBuf Constructor - Creates an empty SWBuf object
+ *
+ */
+ inline SWBuf() {
+ init(0);
+ }
+
/**
- * SWBuf Constructor - Creates an empty SWBuf object or an SWBuf initialized
+ * SWBuf Constructor - Creates an SWBuf initialized
* to a value from a const char *
*
*/
- SWBuf(const char *initVal = 0, unsigned long initSize = 0);
+ SWBuf(const char *initVal, unsigned long initSize = 0);
// SWBuf(unsigned long initSize);
/**
@@ -93,6 +107,15 @@
*
*/
SWBuf(const SWBuf &other, unsigned long initSize = 0);
+
+ /******************************************************************************
+ * SWBuf Destructor - Cleans up instance of SWBuf
+ */
+ inline ~SWBuf() {
+ if ((buf) && (buf != nullStr))
+ free(buf);
+ }
+
/**
* SWBuf::setFillByte - Set the fillByte character
*
@@ -100,6 +123,7 @@
* The memory will be filled with this character. \see setSize() \see resize()
*/
inline void setFillByte(char ch) { fillByte = ch; }
+
/**
* SWBuf::getFillByte - Get the fillByte character
*
@@ -108,11 +132,6 @@
inline char getFillByte() { return fillByte; }
/**
- * SWBuf Destructor - Cleans up instance of SWBuf
- */
- virtual ~SWBuf();
-
- /**
* @return a pointer to the buffer content (null-terminated string)
*/
inline const char *c_str() const{ return buf; }
@@ -121,8 +140,7 @@
* @param pos The position of the requested character.
* @return The character at the specified position
*/
- inline char &charAt(unsigned long pos) { return ((pos <= (unsigned long)(end - buf)) ? buf[pos] : nullStr[0]); }
-// inline char &charAt(unsigned int pos) { return ((buf+pos)<=end) ? buf[pos] : nullStr[0]; }
+ inline char &charAt(unsigned long pos) { return ((pos <= (unsigned long)(end - buf)) ? buf[pos] : ((*junkBuf=0),*junkBuf)); }
/**
* @return size() and length() return only the number of characters of the string.
@@ -137,18 +155,37 @@
inline unsigned long length() const { return end - buf; }
/**
- * SWBuf::set - sets this buf to a new value.
+ * SWBuf::set - sets this buf to a new value
* If the allocated memory is bigger than the new string, it will NOT be resized.
* @param newVal the value to set this buffer to.
*/
- void set(const char *newVal);
+ inline void set(const SWBuf &newVal) {
+ unsigned long len = newVal.length() + 1;
+ assureSize(len);
+// const char *n = newVal.c_str();
+// for (end = buf;len;len--) *end++ = *n++;
+ memcpy(buf, newVal.c_str(), len);
+ end = buf + (len - 1);
+ }
/**
- * SWBuf::set - sets this buf to a new value
+ * SWBuf::set - sets this buf to a new value.
* If the allocated memory is bigger than the new string, it will NOT be resized.
* @param newVal the value to set this buffer to.
*/
- void set(const SWBuf &newVal);
+ inline void set(const char *newVal) {
+ if (newVal) {
+ unsigned long len = strlen(newVal) + 1;
+ assureSize(len);
+ memcpy(buf, newVal, len);
+ end = buf + (len - 1);
+ }
+ else {
+ assureSize(1);
+ end = buf;
+ *end = 0;
+ }
+ }
/**
* SWBuf::setFormatted - sets this buf to a formatted string.
Modified: trunk/src/utilfuns/swbuf.cpp
===================================================================
--- trunk/src/utilfuns/swbuf.cpp 2005-04-30 01:57:10 UTC (rev 1784)
+++ trunk/src/utilfuns/swbuf.cpp 2005-04-30 19:11:12 UTC (rev 1785)
@@ -37,7 +37,8 @@
*/
SWBuf::SWBuf(const char *initVal, unsigned long initSize) {
init(initSize);
- set(initVal);
+ if (initVal)
+ set(initVal);
}
/******************************************************************************
@@ -56,13 +57,10 @@
*
*/
SWBuf::SWBuf(char initVal, unsigned long initSize) {
- init(initSize);
-
- allocSize = 15;
- buf = (char *)calloc(allocSize, 1);
+ init(initSize+1);
*buf = initVal;
end = buf+1;
- endAlloc = buf + allocSize-1;
+ *end = 0;
}
/*
@@ -73,53 +71,7 @@
*/
-void SWBuf::init(unsigned long initSize) {
- fillByte = ' ';
- allocSize = 0;
- endAlloc = 0;
- buf = 0;
- end = 0;
- if (initSize)
- assureSize(initSize);
-}
-
/******************************************************************************
-* SWBuf Destructor - Cleans up instance of SWBuf
-*/
-SWBuf::~SWBuf() {
- if (buf)
- free(buf);
-}
-
-/******************************************************************************
-* SWBuf::set - sets this buf to a new value
-*/
-void SWBuf::set(const char *newVal) {
- if (newVal) {
- unsigned long len = strlen(newVal) + 1;
- assureSize(len);
- memcpy(buf, newVal, len);
- end = buf + (len - 1);
- }
- else {
- assureSize(1);
- end = buf;
- *end = 0;
- }
-}
-
-
-/******************************************************************************
-* SWBuf::set - sets this buf to a new value
-*/
-void SWBuf::set(const SWBuf &newVal) {
- unsigned long len = newVal.length() + 1;
- assureSize(len);
- memcpy(buf, newVal.c_str(), len);
- end = buf + (len-1);
-}
-
-/******************************************************************************
* SWBuf::setFormatted - sets this buf to a formatted string
* WARNING: This function can only write at most
* JUNKBUFSIZE to the string per call.
Modified: trunk/tests/swbuftest.cpp
===================================================================
--- trunk/tests/swbuftest.cpp 2005-04-30 01:57:10 UTC (rev 1784)
+++ trunk/tests/swbuftest.cpp 2005-04-30 19:11:12 UTC (rev 1785)
@@ -1,13 +1,13 @@
#include <time.h>
#include <iostream>
-#define BASEI 256000000L
+#define BASEI 25600000L
-#include <swbuf.h>
-typedef sword::SWBuf StringType;
+//#include <swbuf.h>
+//typedef sword::SWBuf StringType;
-//#include <string>
-//typedef std::string StringType;
+#include <string>
+typedef std::string StringType;
using std::cout;
using std::cerr;
@@ -17,6 +17,7 @@
static clock_t last = start;
clock_t current = clock();
cerr << ((float)(current - last)/CLOCKS_PER_SEC) << " / " << ((float)(current - start)/CLOCKS_PER_SEC) << " (Seconds Delta / Seconds Total)\n";
+ cerr.flush();
last = current;
}
@@ -71,7 +72,7 @@
}
for (unsigned long i = (BASEI); i; i--) {
StringType s2;
- s2 = s;
+ s2 = s.c_str();
s2.c_str(); // keep us from being optimized out
}
cerr << "\nEND: constructor and assign test -------\n";
@@ -131,18 +132,18 @@
// y.append(y.c_str(),5);
// cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!hello): (" << y << ")\n";
+// markTime();
+// appendChTest();
+// markTime();
+// appendStringTest();
+// markTime();
+// subscriptTest();
markTime();
- appendChTest();
- markTime();
- appendStringTest();
- markTime();
- subscriptTest();
- markTime();
ctorAssignTest();
markTime();
- compareTest();
- markTime();
- insertStringTest();
- markTime();
+ // compareTest();
+// markTime();
+// insertStringTest();
+// markTime();
}
Modified: trunk/usrinst.sh
===================================================================
--- trunk/usrinst.sh 2005-04-30 01:57:10 UTC (rev 1784)
+++ trunk/usrinst.sh 2005-04-30 19:11:12 UTC (rev 1785)
@@ -1,17 +1,17 @@
#!/bin/sh
OPTIONS="--prefix=/usr $OPTIONS"
-#OPTIONS="--disable-shared $OPTIONS"
+OPTIONS="--disable-shared $OPTIONS"
OPTIONS="--without-conf $OPTIONS"
OPTIONS="--sysconfdir=/etc $OPTIONS"
#OPTIONS="--with-icu $OPTIONS"
#OPTIONS="--with-vcl $OPTIONS"
#OPTIONS="--enable-debug $OPTIONS"
-#OPTIONS="--enable-profile $OPTIONS"
+OPTIONS="--enable-profile $OPTIONS"
#OPTIONS="--with-lucene $OPTIONS"
#OPTIONS="--without-curl $OPTIONS"
#OPTIONS="--enable-tests $OPTIONS"
-#OPTIONS="--disable-utilities $OPTIONS"
+OPTIONS="--disable-utilities $OPTIONS"
CPPFLAGS="$CFLAGS $CPPFLAGS -DUSBINARY" ./configure $OPTIONS $*
More information about the sword-cvs
mailing list