[sword-cvs] sword/src/utilfuns swbuf.cpp,1.10,1.11

sword@www.crosswire.org sword@www.crosswire.org
Wed, 16 Jul 2003 05:26:11 -0700


Update of /usr/local/cvsroot/sword/src/utilfuns
In directory www:/tmp/cvs-serv24686/src/utilfuns

Modified Files:
	swbuf.cpp 
Log Message:
Some very small optimizations


Index: swbuf.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/utilfuns/swbuf.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- swbuf.cpp	27 Jun 2003 01:41:08 -0000	1.10
+++ swbuf.cpp	16 Jul 2003 12:26:09 -0000	1.11
@@ -35,8 +35,8 @@
 * 		to a value from a const char *
 *
 */
-SWBuf::SWBuf(const char *initVal) {
-	init();
+SWBuf::SWBuf(const char *initVal, unsigned int initSize) {
+	init(initSize);
 	set(initVal);
 }
 
@@ -45,8 +45,8 @@
 * 		to a value from another SWBuf
 *
 */
-SWBuf::SWBuf(const SWBuf &other) {
-	init();
+SWBuf::SWBuf(const SWBuf &other, unsigned int initSize) {
+	init(initSize);
 	set(other);
 }
 
@@ -55,20 +55,24 @@
 * 		to a value from a char
 *
 */
-SWBuf::SWBuf(char initVal) {
-	init();
+SWBuf::SWBuf(char initVal, unsigned int initSize) {
+	init(initSize);
 
 	allocSize = 15;
 	buf = (char *)calloc(allocSize, 1);
 	*buf = initVal;
 	end = buf+1;
+	endAlloc = buf + allocSize-1;
 }
 
-void SWBuf::init() {
+void SWBuf::init(unsigned int initSize) {
 	fillByte = ' ';
 	allocSize = 0;
+	endAlloc = 0;
 	buf = 0;
 	end = 0;
+	if (initSize)
+		assureSize(initSize);
 }
 
 /******************************************************************************
@@ -115,7 +119,7 @@
 	unsigned int len = strlen(str) + 1;
 	if ((max > -1) && (len > max + 1))
 		len = max + 1;
-	assureSize((end-buf)+len);
+	assureMore(len);
 	memcpy(end, str, len-1);
 	end += (len-1);
 	*end = 0;
@@ -143,7 +147,7 @@
 
 	va_start(argptr, format);
 	int len = vsprintf(junkBuf, format, argptr)+1;
-	assureSize((end-buf)+len);
+	assureMore(len);
 	end += vsprintf(end, format, argptr);
 	va_end(argptr);
 }