Title: [152289] trunk/Source/WTF
- Revision
- 152289
- Author
- [email protected]
- Date
- 2013-07-02 06:36:09 -0700 (Tue, 02 Jul 2013)
Log Message
Avoid code duplication inside String::append()
https://bugs.webkit.org/show_bug.cgi?id=118290
Reviewed by Anders Carlsson.
The implementation of 'append(UChar)' had been repeated inside 'append(LChar)',
this duplication is obviated now.
* wtf/text/WTFString.cpp:
(WTF::String::appendInternal):
(WTF::String::append):
* wtf/text/WTFString.h:
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (152288 => 152289)
--- trunk/Source/WTF/ChangeLog 2013-07-02 13:31:27 UTC (rev 152288)
+++ trunk/Source/WTF/ChangeLog 2013-07-02 13:36:09 UTC (rev 152289)
@@ -1,3 +1,18 @@
+2013-07-02 Mikhail Pozdnyakov <[email protected]>
+
+ Avoid code duplication inside String::append()
+ https://bugs.webkit.org/show_bug.cgi?id=118290
+
+ Reviewed by Anders Carlsson.
+
+ The implementation of 'append(UChar)' had been repeated inside 'append(LChar)',
+ this duplication is obviated now.
+
+ * wtf/text/WTFString.cpp:
+ (WTF::String::appendInternal):
+ (WTF::String::append):
+ * wtf/text/WTFString.h:
+
2013-06-28 Anders Carlsson <[email protected]>
Remove String::deprecatedCharactersWithNullTermination() and related code
Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (152288 => 152289)
--- trunk/Source/WTF/wtf/text/WTFString.cpp 2013-07-02 13:31:27 UTC (rev 152288)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp 2013-07-02 13:36:09 UTC (rev 152289)
@@ -119,7 +119,8 @@
}
}
-void String::append(LChar c)
+template <typename CharacterType>
+inline void String::appendInternal(CharacterType c)
{
// FIXME: This is extremely inefficient. So much so that we might want to take this
// out of String's API. We can make it better by optimizing the case where exactly
@@ -137,22 +138,14 @@
m_impl = StringImpl::create(&c, 1);
}
+void String::append(LChar c)
+{
+ appendInternal(c);
+}
+
void String::append(UChar c)
{
- // FIXME: This is extremely inefficient. So much so that we might want to take this
- // out of String's API. We can make it better by optimizing the case where exactly
- // one String is pointing at this StringImpl, but even then it's going to require a
- // call to fastMalloc every single time.
- if (m_impl) {
- UChar* data;
- if (m_impl->length() >= numeric_limits<unsigned>::max())
- CRASH();
- RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length() + 1, data);
- memcpy(data, m_impl->characters(), m_impl->length() * sizeof(UChar));
- data[m_impl->length()] = c;
- m_impl = newImpl.release();
- } else
- m_impl = StringImpl::create(&c, 1);
+ appendInternal(c);
}
int codePointCompare(const String& a, const String& b)
Modified: trunk/Source/WTF/wtf/text/WTFString.h (152288 => 152289)
--- trunk/Source/WTF/wtf/text/WTFString.h 2013-07-02 13:31:27 UTC (rev 152288)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2013-07-02 13:36:09 UTC (rev 152289)
@@ -495,6 +495,9 @@
template <typename CharacterType>
void removeInternal(const CharacterType*, unsigned, int);
+ template <typename CharacterType>
+ void appendInternal(CharacterType);
+
RefPtr<StringImpl> m_impl;
};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes