summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/utils/String16.cpp13
-rw-r--r--libs/utils/String8.cpp17
2 files changed, 26 insertions, 4 deletions
diff --git a/libs/utils/String16.cpp b/libs/utils/String16.cpp
index c856ceb..b09b728 100644
--- a/libs/utils/String16.cpp
+++ b/libs/utils/String16.cpp
@@ -93,6 +93,19 @@ String16::String16()
{
}
+String16::String16(StaticLinkage)
+ : mString(0)
+{
+ // this constructor is used when we can't rely on the static-initializers
+ // having run. In this case we always allocate an empty string. It's less
+ // efficient than using getEmptyString(), but we assume it's uncommon.
+
+ char16_t* data = static_cast<char16_t*>(
+ SharedBuffer::alloc(sizeof(char16_t))->data());
+ data[0] = 0;
+ mString = data;
+}
+
String16::String16(const String16& o)
: mString(o.mString)
{
diff --git a/libs/utils/String8.cpp b/libs/utils/String8.cpp
index 413928a..e852d77 100644
--- a/libs/utils/String8.cpp
+++ b/libs/utils/String8.cpp
@@ -47,16 +47,12 @@ void initialize_string8();
static inline char* getEmptyString()
{
- if (!gEmptyStringBuf) initialize_string8();
-
gEmptyStringBuf->acquire();
return gEmptyString;
}
void initialize_string8()
{
- if (gEmptyStringBuf) return;
-
// HACK: This dummy dependency forces linking libutils Static.cpp,
// which is needed to initialize String8/String16 classes.
// These variables are named for Darwin, but are needed elsewhere too,
@@ -146,6 +142,19 @@ String8::String8()
{
}
+String8::String8(StaticLinkage)
+ : mString(0)
+{
+ // this constructor is used when we can't rely on the static-initializers
+ // having run. In this case we always allocate an empty string. It's less
+ // efficient than using getEmptyString(), but we assume it's uncommon.
+
+ char* data = static_cast<char*>(
+ SharedBuffer::alloc(sizeof(char))->data());
+ data[0] = 0;
+ mString = data;
+}
+
String8::String8(const String8& o)
: mString(o.mString)
{