summaryrefslogtreecommitdiff
path: root/libs/utils/String16.cpp
diff options
context:
space:
mode:
author Mathias Agopian <mathias@google.com> 2013-05-08 16:04:13 -0700
committer Mathias Agopian <mathias@google.com> 2013-05-08 18:13:07 -0700
commit8050299f5b12a8994f323fa5fcfe9199c12e3acf (patch)
tree33763693e41095a2dcb78e3d4e2e7b1553d3a06b /libs/utils/String16.cpp
parent002e1e58dfe19dd3e49a59c6827cbf51573941a2 (diff)
new String8, String16 ctors to initialize empty static strings with static linkage
when libutils is statically linked, the ordering of the static initializer is not guaranteed and therefore it's unsafe to use empty static strings: e.g.: static String8 sThisStaticStringIsNotSafe; instead, this new constructor can be used: static String8 sThisStaticStringIsSafe(kEmptyString); Change-Id: Ia3daf1cab1c97d021c0ee9c2b394b5e27e8d6c0d
Diffstat (limited to 'libs/utils/String16.cpp')
-rw-r--r--libs/utils/String16.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libs/utils/String16.cpp b/libs/utils/String16.cpp
index c856ceb9b2..b09b728adf 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)
{