diff options
author | Aaron <aaron@10gen.com> | 2009-03-25 18:24:22 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-03-25 18:24:22 -0400 |
commit | e5a43008fd7d030d7ca97d427de8a731228a2aa8 (patch) | |
tree | f604e68e026a264437c8f1558b1b261c1aa8e7e7 /util/builder.h | |
parent | 2506307e4306bf679b707c32b184d7e551679494 (diff) | |
download | mongo-e5a43008fd7d030d7ca97d427de8a731228a2aa8.tar.gz |
Build a subobject without recopying the contents
Diffstat (limited to 'util/builder.h')
-rw-r--r-- | util/builder.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/util/builder.h b/util/builder.h index 85e1c3639e5..08b3237c42c 100644 --- a/util/builder.h +++ b/util/builder.h @@ -27,8 +27,12 @@ namespace mongo { class BufBuilder { public: BufBuilder(int initsize = 512) : size(initsize) { - data = (char *) malloc(size); - assert(data); + if ( size > 0 ) { + data = (char *) malloc(size); + assert(data); + } else { + data = 0; + } l = 0; } ~BufBuilder() { @@ -88,7 +92,7 @@ namespace mongo { append( (void *)str.c_str(), str.length() + 1 ); } - int len() { + int len() const { return l; } @@ -99,6 +103,8 @@ namespace mongo { l += by; if ( l > size ) { int a = size * 2; + if ( a == 0 ) + a = 512; if ( l > a ) a = l + 16 * 1024; assert( a < 64 * 1024 * 1024 ); |