Changeset 49840 in webkit
- Timestamp:
- Oct 19, 2009 10:01:32 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r49839 r49840 1 2009-10-19 James Robinson <jamesr@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Better implementation of WebCore::ScriptString for the V8 bindings. 6 7 https://bugs.webkit.org/show_bug.cgi?id=29909 8 9 WebCore::ScriptString is used for XMLHttpRequest's responseText attribute which is 10 shared with JavaScript. Thus, simply using a WebCore::String and copying the value 11 is pretty inefficient, especially since responseText is built up with a sequence of 12 operator+= calls. JSC builds use a JSC::UString to share the buffer when possible, 13 this patch adopts a similar approach for V8. 14 15 No new tests, behavior is unchanged and covered by LayoutTests/http/tests/xmlhttprequest 16 17 * WebCore.gypi: 18 * bindings/v8/ScriptString.h: 19 (WebCore::ScriptString::ScriptString): 20 (WebCore::ScriptString::operator String): 21 (WebCore::ScriptString::isNull): 22 (WebCore::ScriptString::size): 23 (WebCore::ScriptString::operator=): 24 (WebCore::ScriptString::operator+=): 25 (WebCore::ScriptString::v8StringOrNull): 26 * bindings/v8/ScriptStringImpl.cpp: Added. 27 (WebCore::ScriptStringImpl::ScriptStringImpl): 28 (WebCore::ScriptStringImpl::~ScriptStringImpl): 29 (WebCore::ScriptStringImpl::toString): 30 (WebCore::ScriptStringImpl::isNull): 31 (WebCore::ScriptStringImpl::size): 32 (WebCore::ScriptStringImpl::append): 33 * bindings/v8/ScriptStringImpl.h: Added. 34 (WebCore::ScriptStringImpl::ScriptStringImpl): 35 (WebCore::ScriptStringImpl::v8StringHandle): 36 * bindings/v8/custom/V8XMLHttpRequestCustom.cpp: 37 (WebCore::ACCESSOR_GETTER): 38 1 39 2009-10-19 Adam Barth <abarth@webkit.org> 2 40 -
trunk/WebCore/WebCore.gypi
r49778 r49840 772 772 'bindings/v8/ScriptState.cpp', 773 773 'bindings/v8/ScriptString.h', 774 'bindings/v8/ScriptStringImpl.cpp', 775 'bindings/v8/ScriptStringImpl.h', 774 776 'bindings/v8/ScriptValue.cpp', 775 777 'bindings/v8/ScriptValue.h', -
trunk/WebCore/bindings/v8/ScriptString.h
r42568 r49840 33 33 34 34 #include "PlatformString.h" 35 #include "ScriptStringImpl.h" 36 #include "V8Binding.h" 35 37 36 38 namespace WebCore { … … 38 40 class ScriptString { 39 41 public: 40 ScriptString() {}41 ScriptString(const String& s) : m_ str(s) {}42 ScriptString(const char* s) : m_ str(s) {}42 ScriptString() : m_impl(0) {} 43 ScriptString(const String& s) : m_impl(new ScriptStringImpl(s)) {} 44 ScriptString(const char* s) : m_impl(new ScriptStringImpl(s)) {} 43 45 44 operator String() const { return m_ str; }46 operator String() const { return m_impl->toString(); } 45 47 46 bool isNull() const { return m_str.isNull(); }47 size_t size() const { return m_ str.length(); }48 bool isNull() const { return !m_impl.get() || m_impl->isNull(); } 49 size_t size() const { return m_impl->size(); } 48 50 49 51 ScriptString& operator=(const char* s) 50 52 { 51 m_ str = s;53 m_impl = new ScriptStringImpl(s); 52 54 return *this; 53 55 } … … 55 57 ScriptString& operator+=(const String& s) 56 58 { 57 m_ str += s;59 m_impl->append(s); 58 60 return *this; 59 61 } 60 62 63 v8::Handle<v8::Value> v8StringOrNull() const 64 { 65 return isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(m_impl->v8StringHandle()); 66 } 67 61 68 private: 62 String m_str;69 RefPtr<ScriptStringImpl> m_impl; 63 70 }; 64 71 -
trunk/WebCore/bindings/v8/ScriptStringImpl.cpp
r49839 r49840 29 29 */ 30 30 31 #i fndef ScriptString_h32 # define ScriptString_h31 #include "config.h" 32 #include "ScriptStringImpl.h" 33 33 34 #include " PlatformString.h"34 #include "V8Binding.h" 35 35 36 36 namespace WebCore { 37 37 38 class ScriptString { 39 public: 40 ScriptString() {}41 ScriptString(const String& s) : m_str(s) {}42 ScriptString(const char* s) : m_str(s) {}38 ScriptStringImpl::ScriptStringImpl(const String& s) 39 { 40 v8::HandleScope scope; 41 m_handle.set(v8String(s)); 42 } 43 43 44 operator String() const { return m_str; } 44 ScriptStringImpl::ScriptStringImpl(const char* s) 45 { 46 v8::HandleScope scope; 47 m_handle.set(v8::String::New(s)); 48 } 45 49 46 bool isNull() const { return m_str.isNull(); } 47 size_t size() const { return m_str.length(); } 50 String ScriptStringImpl::toString() const 51 { 52 return v8StringToWebCoreString(m_handle.get()); 53 } 48 54 49 ScriptString& operator=(const char* s) 50 { 51 m_str = s; 52 return *this; 53 } 55 bool ScriptStringImpl::isNull() const 56 { 57 return m_handle.get().IsEmpty(); 58 } 54 59 55 ScriptString& operator+=(const String& s) 56 { 57 m_str += s; 58 return *this; 59 } 60 size_t ScriptStringImpl::size() const 61 { 62 return m_handle.get()->Length(); 63 } 60 64 61 private: 62 String m_str; 63 }; 65 void ScriptStringImpl::append(const String& s) 66 { 67 v8::HandleScope scope; 68 if (m_handle.get().IsEmpty()) 69 m_handle.set(v8String(s)); 70 else 71 m_handle.set(v8::String::Concat(m_handle.get(), v8String(s))); 72 } 64 73 65 74 } // namespace WebCore 66 67 #endif // ScriptString_h -
trunk/WebCore/bindings/v8/ScriptStringImpl.h
r49839 r49840 29 29 */ 30 30 31 #ifndef ScriptString _h32 #define ScriptString _h31 #ifndef ScriptStringImpl_h 32 #define ScriptStringImpl_h 33 33 34 #include "OwnHandle.h" 34 35 #include "PlatformString.h" 36 37 #include <v8.h> 35 38 36 39 namespace WebCore { 37 40 38 class ScriptString { 41 // This class is used for strings that tend to be shared with JavaScript frequently. The JSC implementation uses wtf::UString - see bindings/js/ScriptString.h 42 // Currently XMLHttpRequest uses a ScriptString to build up the responseText attribute. As data arrives from the network, it is appended to the ScriptString 43 // via operator+= and a JavaScript readystatechange event is fired. JavaScript can access the responseText attribute of the XMLHttpRequest object. JavaScript 44 // may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WebCore::String and 45 // then parsed as an XML document. 46 // This implementation optimizes for the common case where the responseText is built up with many calls to operator+= before the actual text is queried. 47 class ScriptStringImpl : public RefCounted<ScriptStringImpl> { 39 48 public: 40 ScriptString () {}41 ScriptString (const String& s) : m_str(s) {}42 ScriptString (const char* s) : m_str(s) {}49 ScriptStringImpl() {} 50 ScriptStringImpl(const String& s); 51 ScriptStringImpl(const char* s); 43 52 44 operator String() const { return m_str; }53 String toString() const; 45 54 46 bool isNull() const { return m_str.isNull(); }47 size_t size() const { return m_str.length(); }55 bool isNull() const; 56 size_t size() const; 48 57 49 ScriptString& operator=(const char* s) 50 { 51 m_str = s; 52 return *this; 53 } 58 void append(const String& s); 54 59 55 ScriptString& operator+=(const String& s) 56 { 57 m_str += s; 58 return *this; 59 } 60 v8::Handle<v8::String> v8StringHandle() { return m_handle.get(); } 60 61 61 62 private: 62 String m_str;63 OwnHandle<v8::String> m_handle; 63 64 }; 64 65 65 66 } // namespace WebCore 66 67 67 #endif // ScriptString _h68 #endif // ScriptStringImpl_h -
trunk/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
r48978 r49840 47 47 ACCESSOR_GETTER(XMLHttpRequestResponseText) 48 48 { 49 // FIXME: This is only needed because webkit set this getter as custom.50 // So we need a custom method to avoid forking the IDL file.51 49 INC_STATS("DOM.XMLHttpRequest.responsetext._get"); 52 50 XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, info.Holder()); 53 return v8StringOrNull(xmlHttpRequest->responseText());51 return xmlHttpRequest->responseText().v8StringOrNull(); 54 52 } 55 53
Note: See TracChangeset
for help on using the changeset viewer.