diff options
author | Max Horn | 2008-09-24 20:29:29 +0000 |
---|---|---|
committer | Max Horn | 2008-09-24 20:29:29 +0000 |
commit | f9650f0b6a07d4f6b835f1fe0b89ced58a504fe1 (patch) | |
tree | abe98da44cae14ca7e35ab07998a4e44ddb75250 | |
parent | e377ed856d0f1a054bce255043ce2e99593bc5b4 (diff) | |
download | scummvm-rg350-f9650f0b6a07d4f6b835f1fe0b89ced58a504fe1.tar.gz scummvm-rg350-f9650f0b6a07d4f6b835f1fe0b89ced58a504fe1.tar.bz2 scummvm-rg350-f9650f0b6a07d4f6b835f1fe0b89ced58a504fe1.zip |
Changed Common::String to use a MemoryPool for its refcounts
svn-id: r34642
-rw-r--r-- | common/str.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/common/str.cpp b/common/str.cpp index d1fed68844..6c48738533 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -26,6 +26,13 @@ #include "common/hash-str.h" #include "common/util.h" +#include "common/memorypool.h" + +#if !defined(__SYMBIAN32__) +#include <new> +#endif + + namespace Common { #if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__)) @@ -34,6 +41,9 @@ const String String::emptyString; const char *String::emptyString = ""; #endif + +MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now + static uint32 computeCapacity(uint32 len) { // By default, for the capacity we use the next multiple of 32 return ((len + 32 - 1) & ~0x1F); @@ -180,7 +190,11 @@ void String::ensureCapacity(uint32 new_size, bool keep_old) { void String::incRefCount() const { assert(!isStorageIntern()); if (_extern._refCount == 0) { - _extern._refCount = new int(2); + if (g_refCountPool == 0) + g_refCountPool = new MemoryPool(sizeof(int)); + + _extern._refCount = (int *)g_refCountPool->malloc(); + *_extern._refCount = 2; } else { ++(*_extern._refCount); } @@ -196,7 +210,10 @@ void String::decRefCount(int *oldRefCount) { if (!oldRefCount || *oldRefCount <= 0) { // The ref count reached zero, so we free the string storage // and the ref count storage. - delete oldRefCount; + if (oldRefCount) { + assert(g_refCountPool); + g_refCountPool->free(oldRefCount); + } free(_str); // Even though _str points to a freed memory block now, |