2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef _SUPPORT_BSTRING_PRIVATE_H_
6 #define _SUPPORT_BSTRING_PRIVATE_H_
14 class BString::Private
{
16 static const uint32 kPrivateDataOffset
= 2 * sizeof(int32
);
19 Private(const BString
& string
)
27 return fString
.fPrivateData
;
30 bool IsShareable() const
32 return fString
._IsShareable();
35 static int32
& DataRefCount(char* data
)
37 return *(((int32
*)data
) - 2);
42 return DataRefCount(Data());
45 static int32
& DataLength(char* data
)
47 return *(((int32
*)data
) - 1);
52 return DataLength(Data());
55 static void IncrementDataRefCount(char* data
)
58 atomic_add(&DataRefCount(data
), 1);
61 static void DecrementDataRefCount(char* data
)
64 if (atomic_add(&DataRefCount(data
), -1) == 1)
65 free(data
- kPrivateDataOffset
);
69 static BString
StringFromData(char* data
)
71 return BString(data
, BString::PRIVATE_DATA
);
75 const BString
& fString
;
79 #endif // _SUPPORT_BSTRING_PRIVATE_H_