[Scummvm-cvs-logs] SF.net SVN: scummvm:[34642] scummvm/trunk/common/str.cpp
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Sep 24 22:29:30 CEST 2008
Revision: 34642
http://scummvm.svn.sourceforge.net/scummvm/?rev=34642&view=rev
Author: fingolfin
Date: 2008-09-24 20:29:29 +0000 (Wed, 24 Sep 2008)
Log Message:
-----------
Changed Common::String to use a MemoryPool for its refcounts
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2008-09-24 18:37:19 UTC (rev 34641)
+++ scummvm/trunk/common/str.cpp 2008-09-24 20:29:29 UTC (rev 34642)
@@ -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 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::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 @@
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,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list