Allocate and grow Common::String objects in multiples of 32, and leave at least 16 spare bytes at the end, in case the string grows a little bit.
svn-id: r22896
This commit is contained in:
parent
9b08aefbb3
commit
cbe66f3360
2 changed files with 49 additions and 26 deletions
11
common/str.h
11
common/str.h
|
@ -32,10 +32,10 @@ namespace Common {
|
|||
|
||||
class String {
|
||||
protected:
|
||||
char *_str;
|
||||
int _len;
|
||||
int *_refCount;
|
||||
int _capacity;
|
||||
char *_str;
|
||||
int _len;
|
||||
mutable int *_refCount;
|
||||
int _capacity;
|
||||
|
||||
public:
|
||||
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
static const char *emptyString;
|
||||
#endif
|
||||
|
||||
String() : _str(0), _len(0), _capacity(0) { _refCount = new int(1); }
|
||||
String() : _str(0), _len(0), _refCount(0), _capacity(0) { incRefCount(); }
|
||||
String(const char *str, int len = -1, int capacity = 16);
|
||||
String(const String &str);
|
||||
virtual ~String();
|
||||
|
@ -114,6 +114,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ensureCapacity(int new_len, bool keep_old);
|
||||
void incRefCount() const;
|
||||
void decRefCount();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue