Index: Source/core/html/parser/HTMLParserIdioms.cpp |
diff --git a/Source/core/html/parser/HTMLParserIdioms.cpp b/Source/core/html/parser/HTMLParserIdioms.cpp |
index e3b143aaf2181cc7646c1968f6c36a489a533fee..14c6eb6ffa6b6d9e2adaa2a85a3612b6878395a4 100644 |
--- a/Source/core/html/parser/HTMLParserIdioms.cpp |
+++ b/Source/core/html/parser/HTMLParserIdioms.cpp |
@@ -374,7 +374,8 @@ bool threadSafeMatch(const String& localName, const QualifiedName& qName) |
return threadSafeEqual(localName.impl(), qName.localName().impl()); |
} |
-StringImpl* findStringIfStatic(const UChar* characters, unsigned length) |
+template<typename CharType> |
+inline StringImpl* findStringIfStatic(const CharType* characters, unsigned length) |
{ |
// We don't need to try hashing if we know the string is too long. |
if (length > StringImpl::highestStaticStringLength()) |
@@ -396,4 +397,27 @@ StringImpl* findStringIfStatic(const UChar* characters, unsigned length) |
return it->value; |
} |
+String attemptStaticStringCreation(const LChar* characters, size_t size) |
+{ |
+ String string(findStringIfStatic(characters, size)); |
+ if (string.impl()) |
+ return string; |
+ return String(characters, size); |
+} |
+ |
+String attemptStaticStringCreation(const UChar* characters, size_t size, CharacterWidth width) |
+{ |
+ String string(findStringIfStatic(characters, size)); |
+ if (string.impl()) |
+ return string; |
+ if (width == Likely8Bit) |
+ string = StringImpl::create8BitIfPossible(characters, size); |
+ else if (width == Force8Bit) |
+ string = String::make8BitFrom16BitSource(characters, size); |
+ else |
+ string = String(characters, size); |
+ |
+ return string; |
+} |
+ |
} |