summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/text/StringImpl.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-18 14:56:50 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commit0c6d523c02dafb95b0683b88222e17a4fa6782a6 (patch)
treed162284bb5f2b5791247db968b9fea1a85a3a356 /Source/WTF/wtf/text/StringImpl.cpp
parent2925efd2fcef1f8b9fd48979144877c1a5ec214b (diff)
downloadqtwebkit-0c6d523c02dafb95b0683b88222e17a4fa6782a6.tar.gz
QtWebKit should not require SQLite version to 3.6.16.
Revert r152134 which raised the minimum SQLite version, and r152201 which removed a method the reverted code needed. Change-Id: Ie028992137f3983d114f3491423afe6303173544 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WTF/wtf/text/StringImpl.cpp')
-rw-r--r--Source/WTF/wtf/text/StringImpl.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/Source/WTF/wtf/text/StringImpl.cpp b/Source/WTF/wtf/text/StringImpl.cpp
index d1a3b56e8..5e6533e64 100644
--- a/Source/WTF/wtf/text/StringImpl.cpp
+++ b/Source/WTF/wtf/text/StringImpl.cpp
@@ -158,7 +158,7 @@ PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters, uns
{
ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty string");
ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(characters), length));
- return adoptRef(new StringImpl(reinterpret_cast<const LChar*>(characters), length, ConstructWithoutCopying));
+ return adoptRef(new StringImpl(reinterpret_cast<const LChar*>(characters), length, DoesHaveTerminatingNullCharacter, ConstructWithoutCopying));
}
PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters)
@@ -166,20 +166,20 @@ PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters)
return createFromLiteral(characters, strlen(characters));
}
-PassRefPtr<StringImpl> StringImpl::createWithoutCopying(const UChar* characters, unsigned length)
+PassRefPtr<StringImpl> StringImpl::createWithoutCopying(const UChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter)
{
if (!length)
return empty();
- return adoptRef(new StringImpl(characters, length, ConstructWithoutCopying));
+ return adoptRef(new StringImpl(characters, length, hasTerminatingNullCharacter, ConstructWithoutCopying));
}
-PassRefPtr<StringImpl> StringImpl::createWithoutCopying(const LChar* characters, unsigned length)
+PassRefPtr<StringImpl> StringImpl::createWithoutCopying(const LChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter)
{
if (!length)
return empty();
- return adoptRef(new StringImpl(characters, length, ConstructWithoutCopying));
+ return adoptRef(new StringImpl(characters, length, hasTerminatingNullCharacter, ConstructWithoutCopying));
}
template <typename CharType>
@@ -315,6 +315,8 @@ const UChar* StringImpl::getData16SlowCase() const
STRING_STATS_ADD_UPCONVERTED_STRING(m_length);
unsigned len = length();
+ if (hasTerminatingNullCharacter())
+ ++len;
m_copyData16 = static_cast<UChar*>(fastMalloc(len * sizeof(UChar)));
@@ -1935,6 +1937,30 @@ PassRefPtr<StringImpl> StringImpl::adopt(QStringData* qStringData)
}
#endif
+PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const StringImpl& string)
+{
+ // Use createUninitialized instead of 'new StringImpl' so that the string and its buffer
+ // get allocated in a single memory block.
+ unsigned length = string.m_length;
+ if (length >= numeric_limits<unsigned>::max())
+ CRASH();
+ RefPtr<StringImpl> terminatedString;
+ if (string.is8Bit()) {
+ LChar* data;
+ terminatedString = createUninitialized(length + 1, data);
+ memcpy(data, string.m_data8, length * sizeof(LChar));
+ data[length] = 0;
+ } else {
+ UChar* data;
+ terminatedString = createUninitialized(length + 1, data);
+ memcpy(data, string.m_data16, length * sizeof(UChar));
+ data[length] = 0;
+ }
+ --(terminatedString->m_length);
+ terminatedString->m_hashAndFlags = (string.m_hashAndFlags & (~s_flagMask | s_hashFlag8BitBuffer)) | s_hashFlagHasTerminatingNullCharacter;
+ return terminatedString.release();
+}
+
size_t StringImpl::sizeInBytes() const
{
// FIXME: support substrings
@@ -1942,6 +1968,8 @@ size_t StringImpl::sizeInBytes() const
if (is8Bit()) {
if (has16BitShadow()) {
size += 2 * size;
+ if (hasTerminatingNullCharacter())
+ size += 2;
}
} else
size *= 2;