Changeset 161518 in webkit
- Timestamp:
- Jan 8, 2014 1:19:21 PM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r161451 r161518 1 2014-01-08 Anders Carlsson <andersca@apple.com> 2 3 Add WTF::StringView and use it for grammar checking 4 https://bugs.webkit.org/show_bug.cgi?id=126644 5 6 Reviewed by Antti Koivisto. 7 8 Add a new StringView class which is an immutable reference to either an 8-bit or a 16-bit string. 9 10 This makes it easier to pass substrings around without having to either copy string data 11 or upconvert and use UChar pointers. 12 13 The StringView class is very loosely based on the std::string_view class which is proposed for a future version of C++, 14 see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3609.html for more details. 15 16 * GNUmakefile.list.am: 17 * WTF.vcxproj/WTF.vcxproj: 18 * WTF.vcxproj/WTF.vcxproj.filters: 19 * WTF.xcodeproj/project.pbxproj: 20 * wtf/CMakeLists.txt: 21 * wtf/Forward.h: 22 * wtf/text/StringView.h: Added. 23 (WTF::StringView::StringView): 24 (WTF::StringView::empty): 25 (WTF::StringView::characters8): 26 (WTF::StringView::characters16): 27 (WTF::StringView::isEmpty): 28 (WTF::StringView::length): 29 (WTF::StringView::is8Bit): 30 (WTF::StringView::substring): 31 (WTF::StringView::toString): 32 (WTF::StringView::toStringWithoutCopying): 33 (WTF::StringView::encodedCharacters): 34 1 35 2014-01-07 David Farler <dfarler@apple.com> 2 36 -
trunk/Source/WTF/GNUmakefile.list.am
r161173 r161518 158 158 Source/WTF/wtf/StringExtras.h \ 159 159 Source/WTF/wtf/StringHashDumpContext.h \ 160 Source/WTF/wtf/StringHasher.h \ 160 161 Source/WTF/wtf/StringPrintStream.cpp \ 161 162 Source/WTF/wtf/StringPrintStream.h \ 162 Source/WTF/wtf/StringHasher.h \163 163 Source/WTF/wtf/TCPackedCache.h \ 164 164 Source/WTF/wtf/TCPageMap.h \ … … 242 242 Source/WTF/wtf/text/StringOperators.h \ 243 243 Source/WTF/wtf/text/StringStatics.cpp \ 244 Source/WTF/wtf/text/StringView.h \ 244 245 Source/WTF/wtf/text/TextPosition.h \ 245 246 Source/WTF/wtf/text/WTFString.cpp \ -
trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj
r161173 r161518 292 292 <ClInclude Include="..\wtf\text\StringImpl.h" /> 293 293 <ClInclude Include="..\wtf\text\StringOperators.h" /> 294 <ClInclude Include="..\wtf\text\StringView.h" /> 294 295 <ClInclude Include="..\wtf\text\WTFString.h" /> 295 296 <ClInclude Include="..\wtf\Threading.h" /> -
trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters
r161173 r161518 318 318 <ClInclude Include="..\wtf\text\StringOperators.h"> 319 319 <Filter>text</Filter> 320 </ClInclude> 321 <ClInclude Include="..\wtf\text\StringView.h"> 322 <Filter>wtf</Filter> 320 323 </ClInclude> 321 324 <ClInclude Include="..\wtf\text\WTFString.h"> -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r161173 r161518 56 56 1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; }; 57 57 1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; }; 58 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; }; 58 59 1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; }; 59 60 1FA47C8B152502DA00568D1B /* WebCoreThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA47C89152502DA00568D1B /* WebCoreThread.h */; }; … … 323 324 1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; }; 324 325 1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; }; 326 1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = "<group>"; }; 325 327 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = "<group>"; }; 326 328 1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = "<group>"; }; … … 906 908 A8A4732D151A825B004123FF /* WTFString.cpp */, 907 909 A8A4732E151A825B004123FF /* WTFString.h */, 910 1A6EB1DF187D0BD30030126F /* StringView.h */, 908 911 ); 909 912 path = text; … … 1105 1108 A8A47430151A825B004123FF /* TCSpinLock.h in Headers */, 1106 1109 A8A47432151A825B004123FF /* TCSystemAlloc.h in Headers */, 1110 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */, 1107 1111 A8A47433151A825B004123FF /* TemporaryChange.h in Headers */, 1108 1112 A8A47444151A825B004123FF /* TextPosition.h in Headers */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r161173 r161518 135 135 text/StringHash.h 136 136 text/StringImpl.h 137 text/StringView.h 137 138 text/WTFString.h 138 139 -
trunk/Source/WTF/wtf/Forward.h
r161173 r161518 48 48 class StringBuilder; 49 49 class StringImpl; 50 class StringView; 50 51 51 52 } … … 70 71 using WTF::StringBuilder; 71 72 using WTF::StringImpl; 73 using WTF::StringView; 72 74 using WTF::Vector; 73 75 -
trunk/Source/WebCore/ChangeLog
r161506 r161518 1 2014-01-08 Anders Carlsson <andersca@apple.com> 2 3 Add WTF::StringView and use it for grammar checking 4 https://bugs.webkit.org/show_bug.cgi?id=126644 5 6 Reviewed by Antti Koivisto. 7 8 Use a StringView in TextCheckerClient::checkTextOfParagraph to avoid upconverting strings unnecessarily. 9 10 * editing/TextCheckingHelper.cpp: 11 (WebCore::checkTextOfParagraph): 12 Pass a StringView to TextCheckerClient::checkTextOfParagraph. 13 14 * loader/EmptyClients.h: 15 Update for TextCheckerClient changes. 16 17 * platform/text/TextCheckerClient.h: 18 Change TextCheckerClient::checkTextOfParagraph to take a StringView. 19 1 20 2014-01-08 Eric Carlson <eric.carlson@apple.com> 2 21 -
trunk/Source/WebCore/editing/TextCheckingHelper.cpp
r158350 r161518 37 37 #include "VisiblePosition.h" 38 38 #include "VisibleUnits.h" 39 #include <wtf/text/StringView.h> 39 40 40 41 namespace WebCore { … … 640 641 { 641 642 #if USE(UNIFIED_TEXT_CHECKING) 642 client->checkTextOfParagraph(text, length, checkingTypes, results);643 results = client->checkTextOfParagraph(StringView(text, length), checkingTypes); 643 644 #else 644 645 Vector<TextCheckingResult> spellingResult; -
trunk/Source/WebCore/loader/EmptyClients.h
r161342 r161518 43 43 #include "Page.h" 44 44 #include "ResourceError.h" 45 #include <wtf/text/StringView.h> 45 46 46 47 /* … … 426 427 427 428 #if USE(UNIFIED_TEXT_CHECKING) 428 virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) OVERRIDE { };429 virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask) OVERRIDE { return Vector<TextCheckingResult>(); } 429 430 #endif 430 431 -
trunk/Source/WebCore/platform/text/TextCheckerClient.h
r119192 r161518 50 50 51 51 #if USE(UNIFIED_TEXT_CHECKING) 52 virtual void checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) = 0;52 virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) = 0; 53 53 #endif 54 54 -
trunk/Source/WebKit/efl/ChangeLog
r161331 r161518 1 2014-01-08 Anders Carlsson <andersca@apple.com> 2 3 Add WTF::StringView and use it for grammar checking 4 https://bugs.webkit.org/show_bug.cgi?id=126644 5 6 Reviewed by Antti Koivisto. 7 8 Update to match WebCore changes. 9 10 * WebCoreSupport/EditorClientEfl.h: 11 (WebCore::EditorClientEfl::checkTextOfParagraph): 12 1 13 2014-01-05 Jinwoo Song <jinwoo7.song@samsung.com> 2 14 -
trunk/Source/WebKit/efl/WebCoreSupport/EditorClientEfl.h
r159856 r161518 41 41 #include <wtf/Deque.h> 42 42 #include <wtf/Forward.h> 43 #include <wtf/text/StringView.h> 43 44 44 45 struct Ewk_Should_Insert_Node_Event { … … 148 149 virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) { } 149 150 #if USE(UNIFIED_TEXT_CHECKING) 150 virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) {}151 virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) { return Vector<TextCheckingResult>(); } 151 152 #endif 152 153 virtual TextCheckerClient* textChecker() { return this; } -
trunk/Source/WebKit/mac/ChangeLog
r161479 r161518 1 2014-01-08 Anders Carlsson <andersca@apple.com> 2 3 Add WTF::StringView and use it for grammar checking 4 https://bugs.webkit.org/show_bug.cgi?id=126644 5 6 Reviewed by Antti Koivisto. 7 8 * WebCoreSupport/WebEditorClient.h: 9 * WebCoreSupport/WebEditorClient.mm: 10 (WebEditorClient::checkTextOfParagraph): 11 Update to match the new signature. 12 13 (nsStringWithoutCopying): 14 New function that creates an NSString that references StringView data 15 without copying the data. (If this function proves to be useful elsewhere, it could 16 potentially be added to StringView). 17 1 18 2014-01-02 Andy Estes <aestes@apple.com> 2 19 -
trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h
r161185 r161518 160 160 virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE; 161 161 virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE; 162 virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;162 virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE; 163 163 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE; 164 164 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE; … … 174 174 virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE { } 175 175 // Note: checkTextOfParagraph() is implemented. 176 virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;176 virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE; 177 177 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE { } 178 178 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE { } -
trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
r161185 r161518 72 72 #import <wtf/PassRefPtr.h> 73 73 #import <wtf/RunLoop.h> 74 #import <wtf/text/StringView.h> 74 75 #import <wtf/text/WTFString.h> 75 76 … … 875 876 } 876 877 877 void WebEditorClient::checkTextOfParagraph( const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)878 void WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes) 878 879 { 879 880 ASSERT(checkingTypes & NSTextCheckingTypeSpelling); 880 NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO]; 881 NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:textString]; 882 [textString release]; 881 882 NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:nsStringWithoutCopying(string).get()]; 883 884 Vector<TextCheckingResult> results; 885 883 886 for (NSValue *incomingResult in incomingResults) { 884 887 NSRange resultRange = [incomingResult rangeValue]; … … 890 893 results.append(result); 891 894 } 895 896 return results; 892 897 } 893 898 #endif // PLATFORM(IOS) 899 900 static RetainPtr<NSString> nsStringWithoutCopying(StringView stringView) 901 { 902 if (stringView.is8Bit()) 903 return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast<LChar*>(stringView.characters8()) length:stringView.length() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]); 904 905 return adoptNS([[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(stringView.characters16()) length:stringView.length() freeWhenDone:NO]); 906 } 894 907 895 908 #if !PLATFORM(IOS) … … 1043 1056 } 1044 1057 1045 void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) 1046 { 1047 NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO]; 1048 NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL]; 1049 [textString release]; 1050 results = core(incomingResults, checkingTypes); 1058 Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes) 1059 { 1060 auto textString = nsStringWithoutCopying(string); 1061 1062 NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString.get() range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL]; 1063 1064 return core(incomingResults, checkingTypes); 1051 1065 } 1052 1066 -
trunk/Source/WebKit2/ChangeLog
r161497 r161518 1 2014-01-08 Anders Carlsson <andersca@apple.com> 2 3 Add WTF::StringView and use it for grammar checking 4 https://bugs.webkit.org/show_bug.cgi?id=126644 5 6 Reviewed by Antti Koivisto. 7 8 Use a StringView and remove a FIXME. 9 10 * WebProcess/WebCoreSupport/WebEditorClient.cpp: 11 (WebKit::WebEditorClient::checkTextOfParagraph): 12 * WebProcess/WebCoreSupport/WebEditorClient.h: 13 1 14 2014-01-08 Zan Dobersek <zdobersek@igalia.com> 2 15 -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
r161045 r161518 52 52 #include <WebCore/UserTypingGestureIndicator.h> 53 53 #include <wtf/NeverDestroyed.h> 54 #include <wtf/text/StringView.h> 54 55 55 56 using namespace WebCore; … … 443 444 444 445 #if USE(UNIFIED_TEXT_CHECKING) 445 void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) 446 { 447 // FIXME: It would be nice if we wouldn't have to copy the text here. 448 m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(String(text, length), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results)); 446 Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes) 447 { 448 Vector<TextCheckingResult> results; 449 450 m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results)); 451 452 return results; 449 453 } 450 454 #endif -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h
r159856 r161518 140 140 virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE; 141 141 #if USE(UNIFIED_TEXT_CHECKING) 142 virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<WebCore::TextCheckingResult>& results) OVERRIDE;142 virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE; 143 143 #endif 144 144 virtual void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) OVERRIDE;
Note: See TracChangeset
for help on using the changeset viewer.