Commit 7baee1c0 authored by andersca@apple.com's avatar andersca@apple.com

AtomicString(CFStringRef) shouldn't unconditionally create a StringImpl

https://bugs.webkit.org/show_bug.cgi?id=100701

Reviewed by Dan Bernstein.

Source/WebCore:

* WebCore.exp.in:
Export AtomicString::add(CFStringRef).

* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
Add AtomicStringCF.cpp

* platform/text/cf/AtomicStringCF.cpp: Added.
(WTF::AtomicString::add):
When trying to add the atomic string to the table, first try to get a Latin-1 pointer
from the string. Second, try to get a Unicode pointer from the string.
If that also fails, copy the string to a temporary unicode buffer and add it from there.

* platform/text/cf/HyphenationCF.cpp:
(WebCore::::createValueForKey):
Update for AtomicString::createCFString being removed.

Source/WTF:

* wtf/text/AtomicString.h:
(WTF::AtomicString::AtomicString):
Change the constructors that take a CFStringRef and an NSString * to call AtomicString::add(CFStringRef)
and remove AtomicString::createCFString.

(WTF::AtomicString::add):
Add new member function declaration. The definition is in a new file in WebCore, AtomicStringCF.cpp.
Also, fix the overload of add that takes a const char* to call the right other overload instead of itself.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@132858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6b05831f
2012-10-29 Anders Carlsson <andersca@apple.com>
AtomicString(CFStringRef) shouldn't unconditionally create a StringImpl
https://bugs.webkit.org/show_bug.cgi?id=100701
Reviewed by Dan Bernstein.
* wtf/text/AtomicString.h:
(WTF::AtomicString::AtomicString):
Change the constructors that take a CFStringRef and an NSString * to call AtomicString::add(CFStringRef)
and remove AtomicString::createCFString.
(WTF::AtomicString::add):
Add new member function declaration. The definition is in a new file in WebCore, AtomicStringCF.cpp.
Also, fix the overload of add that takes a const char* to call the right other overload instead of itself.
2012-10-29 Adam Barth <abarth@webkit.org>
Unreviewed. Correct my previous patch to disable external SVG
......
......@@ -138,11 +138,10 @@ public:
static void remove(StringImpl*);
#if USE(CF)
AtomicString(CFStringRef s) : m_string(add(String(s).impl())) { }
CFStringRef createCFString() const { return m_string.createCFString(); }
AtomicString(CFStringRef s) : m_string(add(s)) { }
#endif
#ifdef __OBJC__
AtomicString(NSString* s) : m_string(add(String(s).impl())) { }
AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { }
operator NSString*() const { return m_string; }
#endif
#if PLATFORM(QT)
......@@ -173,7 +172,7 @@ private:
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const LChar*, unsigned length);
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length);
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const char*>(s), length); };
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*);
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
......@@ -185,6 +184,10 @@ private:
}
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, unsigned length);
WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> addSlowCase(StringImpl*);
#if USE(CF)
static PassRefPtr<StringImpl> add(CFStringRef);
#endif
WTF_EXPORT_STRING_API static AtomicString fromUTF8Internal(const char*, const char*);
};
......
2012-10-29 Anders Carlsson <andersca@apple.com>
AtomicString(CFStringRef) shouldn't unconditionally create a StringImpl
https://bugs.webkit.org/show_bug.cgi?id=100701
Reviewed by Dan Bernstein.
* WebCore.exp.in:
Export AtomicString::add(CFStringRef).
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
Add AtomicStringCF.cpp
* platform/text/cf/AtomicStringCF.cpp: Added.
(WTF::AtomicString::add):
When trying to add the atomic string to the table, first try to get a Latin-1 pointer
from the string. Second, try to get a Unicode pointer from the string.
If that also fails, copy the string to a temporary unicode buffer and add it from there.
* platform/text/cf/HyphenationCF.cpp:
(WebCore::::createValueForKey):
Update for AtomicString::createCFString being removed.
2012-10-25 Stephen Chenney <schenney@chromium.org>
feImage should not be allowed to self reference
......@@ -2873,8 +2873,9 @@ win32-*|wince* {
mac {
SOURCES += \
platform/text/cf/StringCF.cpp \
platform/cf/SharedBufferCF.cpp \
platform/text/cf/AtomicStringCF.cpp \
platform/text/cf/StringCF.cpp \
platform/text/cf/StringImplCF.cpp
}
......
......@@ -62,6 +62,7 @@ __Z4coreP7DOMNode
__Z4coreP8DOMRange
__ZN3JSC8Bindings8Instance16newRuntimeObjectEPNS_9ExecStateE
__ZN3WTF10StringImplcvP8NSStringEv
__ZN3WTF12AtomicString3addEPK10__CFString
__ZN3WTF6StringC1EP8NSString
__ZN3WTF6StringC1EPK10__CFString
__ZN7WebCore10ClientRectC1ERKNS_7IntRectE
......
......@@ -5752,6 +5752,7 @@
'platform/text/TextEncodingRegistry.cpp',
'platform/text/TextStream.cpp',
'platform/text/UnicodeRange.cpp',
'platform/text/cf/AtomicStringCF.cpp',
'platform/text/cf/HyphenationCF.cpp',
'platform/text/cf/StringCF.cpp',
'platform/text/cf/StringImplCF.cpp',
......
......@@ -34184,6 +34184,10 @@
<Filter
Name="cf"
>
<File
RelativePath="..\platform\text\cf\AtomicStringCF.cpp"
>
</File>
<File
RelativePath="..\platform\text\cf\HyphenationCF.cpp"
>
......@@ -503,6 +503,7 @@
1A927FD31416A15B003A83C8 /* npruntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD01416A15B003A83C8 /* npruntime.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A927FD41416A15B003A83C8 /* nptypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD11416A15B003A83C8 /* nptypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */; };
1AA21250163F0DA80000E63F /* AtomicStringCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA2124F163F0DA80000E63F /* AtomicStringCF.cpp */; };
1AA7160A149BC4DB0016EC19 /* TileCache.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA71608149BC4DA0016EC19 /* TileCache.mm */; };
1AA7160B149BC4DB0016EC19 /* TileCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA71609149BC4DB0016EC19 /* TileCache.h */; };
1AA7161E149BF2FA0016EC19 /* WebTileLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA7161C149BF2FA0016EC19 /* WebTileLayer.mm */; };
......@@ -7606,6 +7607,7 @@
1A927FD01416A15B003A83C8 /* npruntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = npruntime.h; sourceTree = "<group>"; };
1A927FD11416A15B003A83C8 /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = "<group>"; };
1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURLCFNet.cpp; sourceTree = "<group>"; };
1AA2124F163F0DA80000E63F /* AtomicStringCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringCF.cpp; sourceTree = "<group>"; };
1AA71608149BC4DA0016EC19 /* TileCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TileCache.mm; path = ca/mac/TileCache.mm; sourceTree = "<group>"; };
1AA71609149BC4DB0016EC19 /* TileCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TileCache.h; path = ca/mac/TileCache.h; sourceTree = "<group>"; };
1AA7161C149BF2FA0016EC19 /* WebTileLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebTileLayer.mm; path = ca/mac/WebTileLayer.mm; sourceTree = "<group>"; };
......@@ -20077,6 +20079,7 @@
371A67CA11C6C7DB00047B8B /* HyphenationCF.cpp */,
B2B2645A0D00A77E000ACC1D /* StringCF.cpp */,
B2B2645B0D00A77E000ACC1D /* StringImplCF.cpp */,
1AA2124F163F0DA80000E63F /* AtomicStringCF.cpp */,
);
path = cf;
sourceTree = "<group>";
......@@ -28792,6 +28795,7 @@
FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
51ABF64D16392E2800132A7A /* LoaderStrategy.cpp in Sources */,
5093334F163B0E4300099A60 /* CustomFilterParameterList.cpp in Sources */,
1AA21250163F0DA80000E63F /* AtomicStringCF.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/text/AtomicString.h>
#if USE(CF)
#include <wtf/text/CString.h>
namespace WTF {
PassRefPtr<StringImpl> AtomicString::add(CFStringRef string)
{
CFIndex length = CFStringGetLength(string);
if (const LChar* ptr = reinterpret_cast<const LChar*>(CFStringGetCStringPtr(string, kCFStringEncodingISOLatin1)))
return add(ptr, length);
if (const UniChar* ptr = CFStringGetCharactersPtr(string))
return add(reinterpret_cast<const UChar*>(ptr), length);
Vector<UniChar, 1024> ucharBuffer(length);
CFStringGetCharacters(string, CFRangeMake(0, length), ucharBuffer.data());
return add(reinterpret_cast<const UChar*>(ucharBuffer.data()), length);
}
} // namespace WTF
#endif // USE(CF)
......@@ -46,7 +46,7 @@ RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::creat
template<>
RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::createValueForKey(const AtomicString& localeIdentifier)
{
RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, localeIdentifier.createCFString());
RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, localeIdentifier.string().createCFString());
RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCreate(kCFAllocatorDefault, cfLocaleIdentifier.get()));
return CFStringIsHyphenationAvailableForLocale(locale.get()) ? locale : 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment