Diff
Modified: trunk/Source/WTF/ChangeLog (161517 => 161518)
--- trunk/Source/WTF/ChangeLog 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/ChangeLog 2014-01-08 21:19:21 UTC (rev 161518)
@@ -1,3 +1,37 @@
+2014-01-08 Anders Carlsson <[email protected]>
+
+ Add WTF::StringView and use it for grammar checking
+ https://bugs.webkit.org/show_bug.cgi?id=126644
+
+ Reviewed by Antti Koivisto.
+
+ Add a new StringView class which is an immutable reference to either an 8-bit or a 16-bit string.
+
+ This makes it easier to pass substrings around without having to either copy string data
+ or upconvert and use UChar pointers.
+
+ The StringView class is very loosely based on the std::string_view class which is proposed for a future version of C++,
+ see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3609.html for more details.
+
+ * GNUmakefile.list.am:
+ * WTF.vcxproj/WTF.vcxproj:
+ * WTF.vcxproj/WTF.vcxproj.filters:
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ * wtf/Forward.h:
+ * wtf/text/StringView.h: Added.
+ (WTF::StringView::StringView):
+ (WTF::StringView::empty):
+ (WTF::StringView::characters8):
+ (WTF::StringView::characters16):
+ (WTF::StringView::isEmpty):
+ (WTF::StringView::length):
+ (WTF::StringView::is8Bit):
+ (WTF::StringView::substring):
+ (WTF::StringView::toString):
+ (WTF::StringView::toStringWithoutCopying):
+ (WTF::StringView::encodedCharacters):
+
2014-01-07 David Farler <[email protected]>
[ASAN] Building with trunk clang corrupts sandbox profile with comment from Compiler.h
Modified: trunk/Source/WTF/GNUmakefile.list.am (161517 => 161518)
--- trunk/Source/WTF/GNUmakefile.list.am 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/GNUmakefile.list.am 2014-01-08 21:19:21 UTC (rev 161518)
@@ -157,9 +157,9 @@
Source/WTF/wtf/StreamBuffer.h \
Source/WTF/wtf/StringExtras.h \
Source/WTF/wtf/StringHashDumpContext.h \
+ Source/WTF/wtf/StringHasher.h \
Source/WTF/wtf/StringPrintStream.cpp \
Source/WTF/wtf/StringPrintStream.h \
- Source/WTF/wtf/StringHasher.h \
Source/WTF/wtf/TCPackedCache.h \
Source/WTF/wtf/TCPageMap.h \
Source/WTF/wtf/TCSpinLock.h \
@@ -241,6 +241,7 @@
Source/WTF/wtf/text/StringImpl.h \
Source/WTF/wtf/text/StringOperators.h \
Source/WTF/wtf/text/StringStatics.cpp \
+ Source/WTF/wtf/text/StringView.h \
Source/WTF/wtf/text/TextPosition.h \
Source/WTF/wtf/text/WTFString.cpp \
Source/WTF/wtf/text/WTFString.h \
Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (161517 => 161518)
--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj 2014-01-08 21:19:21 UTC (rev 161518)
@@ -291,6 +291,7 @@
<ClInclude Include="..\wtf\text\StringHash.h" />
<ClInclude Include="..\wtf\text\StringImpl.h" />
<ClInclude Include="..\wtf\text\StringOperators.h" />
+ <ClInclude Include="..\wtf\text\StringView.h" />
<ClInclude Include="..\wtf\text\WTFString.h" />
<ClInclude Include="..\wtf\Threading.h" />
<ClInclude Include="..\wtf\ThreadingPrimitives.h" />
Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters (161517 => 161518)
--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters 2014-01-08 21:19:21 UTC (rev 161518)
@@ -318,6 +318,9 @@
<ClInclude Include="..\wtf\text\StringOperators.h">
<Filter>text</Filter>
</ClInclude>
+ <ClInclude Include="..\wtf\text\StringView.h">
+ <Filter>wtf</Filter>
+ </ClInclude>
<ClInclude Include="..\wtf\text\WTFString.h">
<Filter>text</Filter>
</ClInclude>
Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (161517 => 161518)
--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2014-01-08 21:19:21 UTC (rev 161518)
@@ -55,6 +55,7 @@
1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */; };
1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; };
1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
+ 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; };
1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
1FA47C8B152502DA00568D1B /* WebCoreThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA47C89152502DA00568D1B /* WebCoreThread.h */; };
26147B0A15DDCCDC00DDB907 /* IntegerToStringConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */; };
@@ -322,6 +323,7 @@
1A233C7C17DAA6E300A93ACF /* MallocPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocPtr.h; sourceTree = "<group>"; };
1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
+ 1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = "<group>"; };
1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = "<group>"; };
1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = "<group>"; };
26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
@@ -905,6 +907,7 @@
A8A4732C151A825B004123FF /* TextPosition.h */,
A8A4732D151A825B004123FF /* WTFString.cpp */,
A8A4732E151A825B004123FF /* WTFString.h */,
+ 1A6EB1DF187D0BD30030126F /* StringView.h */,
);
path = text;
sourceTree = "<group>";
@@ -1104,6 +1107,7 @@
A8A4742F151A825B004123FF /* TCPageMap.h in Headers */,
A8A47430151A825B004123FF /* TCSpinLock.h in Headers */,
A8A47432151A825B004123FF /* TCSystemAlloc.h in Headers */,
+ 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */,
A8A47433151A825B004123FF /* TemporaryChange.h in Headers */,
A8A47444151A825B004123FF /* TextPosition.h in Headers */,
A8A47447151A825B004123FF /* ThreadFunctionInvocation.h in Headers */,
Modified: trunk/Source/WTF/wtf/CMakeLists.txt (161517 => 161518)
--- trunk/Source/WTF/wtf/CMakeLists.txt 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/wtf/CMakeLists.txt 2014-01-08 21:19:21 UTC (rev 161518)
@@ -134,6 +134,7 @@
text/StringBuffer.h
text/StringHash.h
text/StringImpl.h
+ text/StringView.h
text/WTFString.h
threads/BinarySemaphore.h
Modified: trunk/Source/WTF/wtf/Forward.h (161517 => 161518)
--- trunk/Source/WTF/wtf/Forward.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WTF/wtf/Forward.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -47,6 +47,7 @@
class String;
class StringBuilder;
class StringImpl;
+class StringView;
}
@@ -69,6 +70,7 @@
using WTF::StringBuffer;
using WTF::StringBuilder;
using WTF::StringImpl;
+using WTF::StringView;
using WTF::Vector;
#endif // WTF_Forward_h
Added: trunk/Source/WTF/wtf/text/StringView.h (0 => 161518)
--- trunk/Source/WTF/wtf/text/StringView.h (rev 0)
+++ trunk/Source/WTF/wtf/text/StringView.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#ifndef StringView_h
+#define StringView_h
+
+#include <wtf/text/WTFString.h>
+
+namespace WTF {
+
+// StringView is a non-owning reference to a string, similar to the proposed std::string_view.
+// Whether the string is 8-bit or 16-bit is encoded in the upper bit of the length member.
+// This means that strings longer than 2 Gigabytes can not be represented. If that turns out to be
+// a problem we can investigate alternative solutions.
+
+class StringView {
+public:
+ StringView(const LChar *characters, unsigned length)
+ {
+ initialize(characters, length);
+ }
+
+ StringView(const UChar *characters, unsigned length)
+ {
+ initialize(characters, length);
+ }
+
+ StringView(const String& string)
+ : m_characters(nullptr)
+ , m_length(0)
+ {
+ if (!string.impl())
+ return;
+
+ if (string.is8Bit())
+ initialize(string.characters8(), string.length());
+ else
+ initialize(string.characters16(), string.length());
+ }
+
+ static StringView empty()
+ {
+ return StringView(reinterpret_cast<const LChar*>(""), 0);
+ }
+
+ const LChar* characters8() const
+ {
+ ASSERT(is8Bit());
+
+ return static_cast<const LChar*>(m_characters);
+ }
+
+ const UChar* characters16() const
+ {
+ ASSERT(!is8Bit());
+
+ return static_cast<const UChar*>(m_characters);
+ }
+
+ bool isEmpty() const { return !length(); }
+ unsigned length() const { return m_length & ~is16BitStringFlag; }
+
+ bool is8Bit() const { return !(m_length & is16BitStringFlag); }
+
+ StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const
+ {
+ if (start >= this->length())
+ return empty();
+ unsigned maxLength = this->length() - start;
+
+ if (length >= maxLength) {
+ if (!start)
+ return *this;
+ length = maxLength;
+ }
+
+ if (is8Bit())
+ return StringView(characters8() + start, length);
+
+ return StringView(characters16() + start, length);
+ }
+
+ String toString() const
+ {
+ if (is8Bit())
+ return String(characters8(), length());
+
+ return String(characters16(), length());
+ }
+
+ String toStringWithoutCopying() const
+ {
+ if (is8Bit())
+ return StringImpl::createWithoutCopying(characters8(), length());
+
+ return StringImpl::createWithoutCopying(characters16(), length());
+ }
+
+private:
+ void initialize(const LChar *characters, unsigned length)
+ {
+ ASSERT(!(length & is16BitStringFlag));
+
+ m_characters = characters;
+ m_length = length;
+ }
+
+ void initialize(const UChar *characters, unsigned length)
+ {
+ ASSERT(!(length & is16BitStringFlag));
+
+ m_characters = characters;
+ m_length = is16BitStringFlag | length;
+ }
+
+ static const unsigned is16BitStringFlag = 1u << 31;
+
+ const void* m_characters;
+ unsigned m_length;
+};
+
+} // namespace WTF
+
+using WTF::StringView;
+
+#endif // StringView_h
Modified: trunk/Source/WebCore/ChangeLog (161517 => 161518)
--- trunk/Source/WebCore/ChangeLog 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebCore/ChangeLog 2014-01-08 21:19:21 UTC (rev 161518)
@@ -1,3 +1,22 @@
+2014-01-08 Anders Carlsson <[email protected]>
+
+ Add WTF::StringView and use it for grammar checking
+ https://bugs.webkit.org/show_bug.cgi?id=126644
+
+ Reviewed by Antti Koivisto.
+
+ Use a StringView in TextCheckerClient::checkTextOfParagraph to avoid upconverting strings unnecessarily.
+
+ * editing/TextCheckingHelper.cpp:
+ (WebCore::checkTextOfParagraph):
+ Pass a StringView to TextCheckerClient::checkTextOfParagraph.
+
+ * loader/EmptyClients.h:
+ Update for TextCheckerClient changes.
+
+ * platform/text/TextCheckerClient.h:
+ Change TextCheckerClient::checkTextOfParagraph to take a StringView.
+
2014-01-08 Eric Carlson <[email protected]>
Unreviewed Windows build fix attempt after r161481.
Modified: trunk/Source/WebCore/editing/TextCheckingHelper.cpp (161517 => 161518)
--- trunk/Source/WebCore/editing/TextCheckingHelper.cpp 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.cpp 2014-01-08 21:19:21 UTC (rev 161518)
@@ -36,6 +36,7 @@
#include "TextIterator.h"
#include "VisiblePosition.h"
#include "VisibleUnits.h"
+#include <wtf/text/StringView.h>
namespace WebCore {
@@ -639,7 +640,7 @@
TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
{
#if USE(UNIFIED_TEXT_CHECKING)
- client->checkTextOfParagraph(text, length, checkingTypes, results);
+ results = client->checkTextOfParagraph(StringView(text, length), checkingTypes);
#else
Vector<TextCheckingResult> spellingResult;
if (checkingTypes & TextCheckingTypeSpelling)
Modified: trunk/Source/WebCore/loader/EmptyClients.h (161517 => 161518)
--- trunk/Source/WebCore/loader/EmptyClients.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebCore/loader/EmptyClients.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -42,6 +42,7 @@
#include "InspectorClient.h"
#include "Page.h"
#include "ResourceError.h"
+#include <wtf/text/StringView.h>
/*
This file holds empty Client stubs for use by WebCore.
@@ -425,7 +426,7 @@
virtual void checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*) OVERRIDE { }
#if USE(UNIFIED_TEXT_CHECKING)
- virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) OVERRIDE { };
+ virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask) OVERRIDE { return Vector<TextCheckingResult>(); }
#endif
virtual void getGuessesForWord(const String&, const String&, Vector<String>&) OVERRIDE { }
Modified: trunk/Source/WebCore/platform/text/TextCheckerClient.h (161517 => 161518)
--- trunk/Source/WebCore/platform/text/TextCheckerClient.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebCore/platform/text/TextCheckerClient.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -49,7 +49,7 @@
virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
#if USE(UNIFIED_TEXT_CHECKING)
- virtual void checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) = 0;
+ virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) = 0;
#endif
// For spellcheckers that support multiple languages, it's often important to be able to identify the language in order to
Modified: trunk/Source/WebKit/efl/ChangeLog (161517 => 161518)
--- trunk/Source/WebKit/efl/ChangeLog 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit/efl/ChangeLog 2014-01-08 21:19:21 UTC (rev 161518)
@@ -1,3 +1,15 @@
+2014-01-08 Anders Carlsson <[email protected]>
+
+ Add WTF::StringView and use it for grammar checking
+ https://bugs.webkit.org/show_bug.cgi?id=126644
+
+ Reviewed by Antti Koivisto.
+
+ Update to match WebCore changes.
+
+ * WebCoreSupport/EditorClientEfl.h:
+ (WebCore::EditorClientEfl::checkTextOfParagraph):
+
2014-01-05 Jinwoo Song <[email protected]>
[EFL] Fix failing WebKit1 API test of ewk_view_setting_tiled_backing_store
Modified: trunk/Source/WebKit/efl/WebCoreSupport/EditorClientEfl.h (161517 => 161518)
--- trunk/Source/WebKit/efl/WebCoreSupport/EditorClientEfl.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit/efl/WebCoreSupport/EditorClientEfl.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -40,6 +40,7 @@
#include "TextCheckerClient.h"
#include <wtf/Deque.h>
#include <wtf/Forward.h>
+#include <wtf/text/StringView.h>
struct Ewk_Should_Insert_Node_Event {
WebCore::Node* node;
@@ -147,7 +148,7 @@
virtual void setInputMethodState(bool enabled);
virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) { }
#if USE(UNIFIED_TEXT_CHECKING)
- virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) { }
+ virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) { return Vector<TextCheckingResult>(); }
#endif
virtual TextCheckerClient* textChecker() { return this; }
Modified: trunk/Source/WebKit/mac/ChangeLog (161517 => 161518)
--- trunk/Source/WebKit/mac/ChangeLog 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit/mac/ChangeLog 2014-01-08 21:19:21 UTC (rev 161518)
@@ -1,3 +1,20 @@
+2014-01-08 Anders Carlsson <[email protected]>
+
+ Add WTF::StringView and use it for grammar checking
+ https://bugs.webkit.org/show_bug.cgi?id=126644
+
+ Reviewed by Antti Koivisto.
+
+ * WebCoreSupport/WebEditorClient.h:
+ * WebCoreSupport/WebEditorClient.mm:
+ (WebEditorClient::checkTextOfParagraph):
+ Update to match the new signature.
+
+ (nsStringWithoutCopying):
+ New function that creates an NSString that references StringView data
+ without copying the data. (If this function proves to be useful elsewhere, it could
+ potentially be added to StringView).
+
2014-01-02 Andy Estes <[email protected]>
[iOS] Clean up some exported headers
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (161517 => 161518)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -159,7 +159,7 @@
virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) OVERRIDE;
virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE;
virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE;
- virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
+ virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE;
virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE;
virtual void showSpellingUI(bool show) OVERRIDE;
@@ -173,7 +173,7 @@
virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE { return ""; }
virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE { }
// Note: checkTextOfParagraph() is implemented.
- virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
+ virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE { }
virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE { }
virtual void showSpellingUI(bool show) OVERRIDE { }
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (161517 => 161518)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm 2014-01-08 21:19:21 UTC (rev 161518)
@@ -71,6 +71,7 @@
#import <wtf/MainThread.h>
#import <wtf/PassRefPtr.h>
#import <wtf/RunLoop.h>
+#import <wtf/text/StringView.h>
#import <wtf/text/WTFString.h>
#if PLATFORM(IOS)
@@ -874,12 +875,14 @@
return 0;
}
-void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
+void WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes)
{
ASSERT(checkingTypes & NSTextCheckingTypeSpelling);
- NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO];
- NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:textString];
- [textString release];
+
+ NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:nsStringWithoutCopying(string).get()];
+
+ Vector<TextCheckingResult> results;
+
for (NSValue *incomingResult in incomingResults) {
NSRange resultRange = [incomingResult rangeValue];
ASSERT(resultRange.location != NSNotFound && resultRange.length > 0);
@@ -889,9 +892,19 @@
result.length = resultRange.length;
results.append(result);
}
+
+ return results;
}
#endif // PLATFORM(IOS)
+static RetainPtr<NSString> nsStringWithoutCopying(StringView stringView)
+{
+ if (stringView.is8Bit())
+ return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast<LChar*>(stringView.characters8()) length:stringView.length() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]);
+
+ return adoptNS([[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(stringView.characters16()) length:stringView.length() freeWhenDone:NO]);
+}
+
#if !PLATFORM(IOS)
bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(TextCheckingType type) const
{
@@ -1042,12 +1055,13 @@
return results;
}
-void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
+Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes)
{
- NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO];
- NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL];
- [textString release];
- results = core(incomingResults, checkingTypes);
+ auto textString = nsStringWithoutCopying(string);
+
+ NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString.get() range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL];
+
+ return core(incomingResults, checkingTypes);
}
void WebEditorClient::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
Modified: trunk/Source/WebKit2/ChangeLog (161517 => 161518)
--- trunk/Source/WebKit2/ChangeLog 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit2/ChangeLog 2014-01-08 21:19:21 UTC (rev 161518)
@@ -1,3 +1,16 @@
+2014-01-08 Anders Carlsson <[email protected]>
+
+ Add WTF::StringView and use it for grammar checking
+ https://bugs.webkit.org/show_bug.cgi?id=126644
+
+ Reviewed by Antti Koivisto.
+
+ Use a StringView and remove a FIXME.
+
+ * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+ (WebKit::WebEditorClient::checkTextOfParagraph):
+ * WebProcess/WebCoreSupport/WebEditorClient.h:
+
2014-01-08 Zan Dobersek <[email protected]>
[Automake] Scripts for generated build targets do not necessarily produce their output
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp (161517 => 161518)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp 2014-01-08 21:19:21 UTC (rev 161518)
@@ -51,6 +51,7 @@
#include <WebCore/UndoStep.h>
#include <WebCore/UserTypingGestureIndicator.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringView.h>
using namespace WebCore;
using namespace HTMLNames;
@@ -442,10 +443,13 @@
}
#if USE(UNIFIED_TEXT_CHECKING)
-void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
+Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes)
{
- // FIXME: It would be nice if we wouldn't have to copy the text here.
- m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(String(text, length), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
+ Vector<TextCheckingResult> results;
+
+ m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
+
+ return results;
}
#endif
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (161517 => 161518)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h 2014-01-08 21:03:43 UTC (rev 161517)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h 2014-01-08 21:19:21 UTC (rev 161518)
@@ -139,7 +139,7 @@
virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) OVERRIDE;
virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE;
#if USE(UNIFIED_TEXT_CHECKING)
- virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
+ virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
#endif
virtual void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) OVERRIDE;
virtual void updateSpellingUIWithMisspelledWord(const String&) OVERRIDE;