Leverage Substring to create new AtomicStringImpl for StaticStringImpl and SymbolImpl
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 02:40:45 +0000 (02:40 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 02:40:45 +0000 (02:40 +0000)
commitf3873a85cee3a9f83866c439ef92eb612922cf7b
treef5b36627a3443a01a1596739ff79444cc84f4df8
parent792bb4bfccc8b5d85ae4d548a5680dcafdb9245c
Leverage Substring to create new AtomicStringImpl for StaticStringImpl and SymbolImpl
https://bugs.webkit.org/show_bug.cgi?id=166636

Reviewed by Darin Adler.

Source/WTF:

Previously we always create the full atomic string if we need to create the same string
based on the given value. For example, when generating AtomicStringImpl from the SymbolImpl,
we need to create a new AtomicStringImpl since SymbolImpl never becomes `isAtomic() == true`.
But it is costly.

This patch leverages the substring system of StringImpl. Instead of allocating the completely
duplicate string, we create a substring StringImpl that shares the same content with the
base string.

* wtf/text/AtomicStringImpl.cpp:
(WTF::stringTable):
(WTF::addToStringTable):
(WTF::addSubstring):
(WTF::AtomicStringImpl::addSlowCase):
(WTF::AtomicStringImpl::remove):
(WTF::AtomicStringImpl::lookUpSlowCase):
* wtf/text/StringImpl.h:
(WTF::StringImpl::StaticStringImpl::operator StringImpl&):

Tools:

* TestWebKitAPI/Tests/WTF/StringImpl.cpp:
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210230 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/text/AtomicStringImpl.cpp
Source/WTF/wtf/text/StringImpl.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp