summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fstring.h41
-rw-r--r--src/ito.cpp1
-rw-r--r--src/server.cpp1
-rw-r--r--src/serversocket.cpp11
-rw-r--r--src/socket.cpp1
-rw-r--r--src/tests/fstring.cpp4
-rw-r--r--src/unit/fstring.cpp9
7 files changed, 54 insertions, 14 deletions
diff --git a/src/fstring.h b/src/fstring.h
index 72ac99d..4dee537 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -25,11 +25,11 @@ namespace Bu
25 * generation in mind. Like the standard string class you can specify what 25 * generation in mind. Like the standard string class you can specify what
26 * datatype to use for each character. Unlike the standard string class, 26 * datatype to use for each character. Unlike the standard string class,
27 * collection of appended and prepended terms is done lazily, making long 27 * collection of appended and prepended terms is done lazily, making long
28 * operations that involve many appends very inexpensive. In addition internal 28 * operations that involve many appends very inexpensive. In addition
29 * ref-counting means that if you pass strings around between functions there's 29 * internal ref-counting means that if you pass strings around between
30 * almost no overhead in time or memory since a reference is created and no 30 * functions there's almost no overhead in time or memory since a reference
31 * data is actually copied. This also means that you never need to put any 31 * is created and no data is actually copied. This also means that you
32 * FBasicString into a ref-counting container class. 32 * never need to put any FBasicString into a ref-counting container class.
33 * 33 *
34 *@param chr (typename) Type of character (i.e. char) 34 *@param chr (typename) Type of character (i.e. char)
35 *@param nMinSize (int) Chunk size (default: 256) 35 *@param nMinSize (int) Chunk size (default: 256)
@@ -126,7 +126,7 @@ namespace Bu
126 for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); 126 for( nLen = 0; pData[nLen] != (chr)0; nLen++ );
127 if( nLen == 0 ) 127 if( nLen == 0 )
128 return; 128 return;
129 129
130 Chunk *pNew = newChunk( nLen ); 130 Chunk *pNew = newChunk( nLen );
131 cpy( pNew->pData, pData, nLen ); 131 cpy( pNew->pData, pData, nLen );
132 132
@@ -156,7 +156,16 @@ namespace Bu
156 */ 156 */
157 void append( const chr &cData ) 157 void append( const chr &cData )
158 { 158 {
159 append( &cData, 1 ); 159 if( pLast && pLast->nLength < nMinSize )
160 {
161 pLast->pData[pLast->nLength] = cData;
162 ++pLast->nLength; ++nLength;
163 // pLast->pData[pLast->nLength] = (chr)0;
164 }
165 else
166 {
167 append( &cData, 1 );
168 }
160 } 169 }
161 170
162 /** 171 /**
@@ -323,11 +332,21 @@ namespace Bu
323 * Plus equals operator for FString. 332 * Plus equals operator for FString.
324 *@param pData (const chr) The character to append to your FString. 333 *@param pData (const chr) The character to append to your FString.
325 */ 334 */
326 MyType &operator +=( const chr pData ) 335 MyType &operator +=( const chr cData )
327 { 336 {
328 append( &pData, 1 ); 337 if( pLast && pLast->nLength < nMinSize )
338 {
339 pLast->pData[pLast->nLength] = cData;
340 ++pLast->nLength; ++nLength;
341 // pLast->pData[pLast->nLength] = (chr)0;
342 }
343 else
344 {
345 append( &cData, 1 );
346 }
347 //append( pData );
329 348
330 return (*this); 349 //return (*this);
331 } 350 }
332 351
333 /** 352 /**
@@ -714,7 +733,7 @@ namespace Bu
714 Chunk *pNew = aChunk.allocate( 1 ); 733 Chunk *pNew = aChunk.allocate( 1 );
715 pNew->pNext = NULL; 734 pNew->pNext = NULL;
716 pNew->nLength = nLen; 735 pNew->nLength = nLen;
717 pNew->pData = aChr.allocate( nLen+1 ); 736 pNew->pData = aChr.allocate( (nLen<nMinSize)?(nMinSize):(nLen)+1 );
718 pNew->pData[nLen] = (chr)0; 737 pNew->pData[nLen] = (chr)0;
719 return pNew; 738 return pNew;
720 } 739 }
diff --git a/src/ito.cpp b/src/ito.cpp
index 001ca06..231e822 100644
--- a/src/ito.cpp
+++ b/src/ito.cpp
@@ -1,4 +1,5 @@
1#include "ito.h" 1#include "ito.h"
2#include "osx_compatibility.h"
2 3
3Bu::Ito::Ito() 4Bu::Ito::Ito()
4{ 5{
diff --git a/src/server.cpp b/src/server.cpp
index d07a597..53b4301 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -3,6 +3,7 @@
3#include "bu/serversocket.h" 3#include "bu/serversocket.h"
4#include "bu/client.h" 4#include "bu/client.h"
5#include "bu/socket.h" 5#include "bu/socket.h"
6#include "osx_compatibility.h"
6 7
7Bu::Server::Server() : 8Bu::Server::Server() :
8 nTimeoutSec( 0 ), 9 nTimeoutSec( 0 ),
diff --git a/src/serversocket.cpp b/src/serversocket.cpp
index 1424630..010c562 100644
--- a/src/serversocket.cpp
+++ b/src/serversocket.cpp
@@ -13,6 +13,7 @@
13#include <fcntl.h> 13#include <fcntl.h>
14#include "serversocket.h" 14#include "serversocket.h"
15#include "exceptions.h" 15#include "exceptions.h"
16#include "osx_compatibility.h"
16 17
17Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : 18Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) :
18 nPort( nPort ) 19 nPort( nPort )
@@ -117,9 +118,13 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
117 nClient = ::accept( nServer, (struct sockaddr *)&clientname, 118 nClient = ::accept( nServer, (struct sockaddr *)&clientname,
118 (int *)&size 119 (int *)&size
119 ); 120 );
120#else 121#else /* not-cygwin */
121 nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); 122#ifdef __APPLE__
122#endif 123 nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size );
124#else /* linux */
125 nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size );
126#endif /* __APPLE__ */
127#endif /* __CYGWIN__ */
123 if( nClient < 0 ) 128 if( nClient < 0 )
124 { 129 {
125 throw SocketException( 130 throw SocketException(
diff --git a/src/socket.cpp b/src/socket.cpp
index 50ed4e2..ce4ee82 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -13,6 +13,7 @@
13#include <fcntl.h> 13#include <fcntl.h>
14#include "socket.h" 14#include "socket.h"
15#include "exceptions.h" 15#include "exceptions.h"
16#include "osx_compatibility.h"
16 17
17#define RBS (1024*2) 18#define RBS (1024*2)
18 19
diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp
index 48dfc5f..11f147d 100644
--- a/src/tests/fstring.cpp
+++ b/src/tests/fstring.cpp
@@ -110,6 +110,10 @@ void doTimings()
110#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); 110#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() );
111int main( int argc, char *argv ) 111int main( int argc, char *argv )
112{ 112{
113 Bu::FString fs1;
114 for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26));
115 return 0;
116
113 Bu::FString str("th"); 117 Bu::FString str("th");
114 118
115 str.prepend("Hello "); 119 str.prepend("Hello ");
diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp
index 2c6bf7a..462ce5e 100644
--- a/src/unit/fstring.cpp
+++ b/src/unit/fstring.cpp
@@ -9,6 +9,7 @@ public:
9 setName("FString"); 9 setName("FString");
10 addTest( Unit::compare1 ); 10 addTest( Unit::compare1 );
11 addTest( Unit::compare2 ); 11 addTest( Unit::compare2 );
12 addTest( Unit::appendSingle );
12 } 13 }
13 14
14 virtual ~Unit() 15 virtual ~Unit()
@@ -28,6 +29,14 @@ public:
28 unitTest( !(b == "Bob") ); 29 unitTest( !(b == "Bob") );
29 unitTest( b == "Bobo" ); 30 unitTest( b == "Bobo" );
30 } 31 }
32
33 void appendSingle()
34 {
35 Bu::FString b;
36 for( char l = 'a'; l < 'g'; l++ )
37 b += l;
38 unitTest( b == "abcdef" );
39 }
31}; 40};
32 41
33int main( int argc, char *argv[] ) 42int main( int argc, char *argv[] )