Commit f2c9273f authored by esprehn's avatar esprehn Committed by Commit bot

Use StringView in Dictionary and DictionaryHelper.

This lets us avoid all of the string copies and externalization costs for the
key names when getting properties.

BUG=615174

Review-Url: https://codereview.chromium.org/2285183005
Cr-Commit-Position: refs/heads/master@{#415549}
parent 6d007925
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "bindings/core/v8/ScriptController.h" #include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/V8ArrayBufferView.h" #include "bindings/core/v8/V8ArrayBufferView.h"
#include "bindings/core/v8/V8Binding.h" #include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingMacros.h"
#include "bindings/core/v8/V8DOMError.h" #include "bindings/core/v8/V8DOMError.h"
#include "bindings/core/v8/V8Element.h" #include "bindings/core/v8/V8Element.h"
#include "bindings/core/v8/V8EventTarget.h" #include "bindings/core/v8/V8EventTarget.h"
...@@ -61,7 +62,7 @@ bool Dictionary::isUndefinedOrNull() const ...@@ -61,7 +62,7 @@ bool Dictionary::isUndefinedOrNull() const
return blink::isUndefinedOrNull(m_options); return blink::isUndefinedOrNull(m_options);
} }
bool Dictionary::hasProperty(const String& key) const bool Dictionary::hasProperty(const StringView& key) const
{ {
v8::Local<v8::Object> object; v8::Local<v8::Object> object;
if (!toObject(object)) if (!toObject(object))
...@@ -69,15 +70,13 @@ bool Dictionary::hasProperty(const String& key) const ...@@ -69,15 +70,13 @@ bool Dictionary::hasProperty(const String& key) const
DCHECK(m_isolate); DCHECK(m_isolate);
DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
v8::Local<v8::String> v8Key = v8String(m_isolate, key); return v8CallBoolean(object->Has(v8Context(), v8String(m_isolate, key)));
return v8CallBoolean(object->Has(v8Context(), v8Key));
} }
bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const bool Dictionary::get(const StringView& key, v8::Local<v8::Value>& value) const
{ {
if (!m_isolate) if (!m_isolate)
return false; return false;
return getInternal(v8String(m_isolate, key), value); return getInternal(v8String(m_isolate, key), value);
} }
...@@ -95,15 +94,10 @@ DictionaryIterator Dictionary::getIterator(ExecutionContext* executionContext) c ...@@ -95,15 +94,10 @@ DictionaryIterator Dictionary::getIterator(ExecutionContext* executionContext) c
return DictionaryIterator(v8::Local<v8::Object>::Cast(iterator), m_isolate); return DictionaryIterator(v8::Local<v8::Object>::Cast(iterator), m_isolate);
} }
bool Dictionary::get(const String& key, v8::Local<v8::Value>& value) const bool Dictionary::get(const StringView& key, Dictionary& value) const
{
return getKey(key, value);
}
bool Dictionary::get(const String& key, Dictionary& value) const
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!getKey(key, v8Value)) if (!get(key, v8Value))
return false; return false;
if (v8Value->IsObject()) { if (v8Value->IsObject()) {
......
...@@ -29,15 +29,11 @@ ...@@ -29,15 +29,11 @@
#include "bindings/core/v8/DictionaryIterator.h" #include "bindings/core/v8/DictionaryIterator.h"
#include "bindings/core/v8/ExceptionMessages.h" #include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/Nullable.h" #include "bindings/core/v8/Nullable.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h" #include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingMacros.h"
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/Vector.h" #include "wtf/Vector.h"
#include "wtf/text/AtomicString.h" #include "wtf/text/StringView.h"
#include "wtf/text/WTFString.h"
#include <v8.h> #include <v8.h>
namespace blink { namespace blink {
...@@ -67,15 +63,15 @@ public: ...@@ -67,15 +63,15 @@ public:
bool isObject() const; bool isObject() const;
bool isUndefinedOrNull() const; bool isUndefinedOrNull() const;
bool get(const String&, Dictionary&) const; bool get(const StringView&, Dictionary&) const;
bool get(const String&, v8::Local<v8::Value>&) const; bool get(const StringView&, v8::Local<v8::Value>&) const;
v8::Local<v8::Value> v8Value() const { return m_options; } v8::Local<v8::Value> v8Value() const { return m_options; }
bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const;
bool getPropertyNames(Vector<String>&) const; bool getPropertyNames(Vector<String>&) const;
bool hasProperty(const String&) const; bool hasProperty(const StringView&) const;
v8::Isolate* isolate() const { return m_isolate; } v8::Isolate* isolate() const { return m_isolate; }
v8::Local<v8::Context> v8Context() const v8::Local<v8::Context> v8Context() const
...@@ -84,7 +80,6 @@ public: ...@@ -84,7 +80,6 @@ public:
return m_isolate->GetCurrentContext(); return m_isolate->GetCurrentContext();
} }
bool getKey(const String& key, v8::Local<v8::Value>&) const;
DictionaryIterator getIterator(ExecutionContext*) const; DictionaryIterator getIterator(ExecutionContext*) const;
private: private:
...@@ -108,21 +103,21 @@ struct NativeValueTraits<Dictionary> { ...@@ -108,21 +103,21 @@ struct NativeValueTraits<Dictionary> {
struct DictionaryHelper { struct DictionaryHelper {
STATIC_ONLY(DictionaryHelper); STATIC_ONLY(DictionaryHelper);
template <typename T> template <typename T>
static bool get(const Dictionary&, const String& key, T& value); static bool get(const Dictionary&, const StringView& key, T& value);
template <typename T> template <typename T>
static bool get(const Dictionary&, const String& key, T& value, bool& hasValue); static bool get(const Dictionary&, const StringView& key, T& value, bool& hasValue);
template <typename T> template <typename T>
static bool get(const Dictionary&, const String& key, T& value, ExceptionState&); static bool get(const Dictionary&, const StringView& key, T& value, ExceptionState&);
template <typename T> template <typename T>
static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const String& key, T& value) static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const StringView& key, T& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) if (!dictionary.get(key, v8Value) || isUndefinedOrNull(v8Value))
return false; return false;
return DictionaryHelper::get(dictionary, key, value); return DictionaryHelper::get(dictionary, key, value);
} }
template <template <typename> class PointerType, typename T> template <template <typename> class PointerType, typename T>
static bool get(const Dictionary&, const String& key, PointerType<T>& value); static bool get(const Dictionary&, const StringView& key, PointerType<T>& value);
}; };
} // namespace blink } // namespace blink
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
namespace blink { namespace blink {
template <template <typename> class PointerType, typename T> template <template <typename> class PointerType, typename T>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, PointerType<T>& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, PointerType<T>& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
......
...@@ -43,19 +43,19 @@ ...@@ -43,19 +43,19 @@
namespace blink { namespace blink {
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, v8::Local<v8::Value>& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, v8::Local<v8::Value>& value)
{ {
return dictionary.get(key, value); return dictionary.get(key, value);
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Dictionary& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Dictionary& value)
{ {
return dictionary.get(key, value); return dictionary.get(key, value);
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, bool& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, bool& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -65,7 +65,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -65,7 +65,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, int32_t& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, int32_t& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -75,7 +75,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -75,7 +75,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, double& value, bool& hasValue) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, double& value, bool& hasValue)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) { if (!dictionary.get(key, v8Value)) {
...@@ -88,14 +88,14 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -88,14 +88,14 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, double& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, double& value)
{ {
bool unused; bool unused;
return DictionaryHelper::get(dictionary, key, value, unused); return DictionaryHelper::get(dictionary, key, value, unused);
} }
template<typename StringType> template<typename StringType>
bool getStringType(const Dictionary& dictionary, const String& key, StringType& value) bool getStringType(const Dictionary& dictionary, const StringView& key, StringType& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -109,19 +109,19 @@ bool getStringType(const Dictionary& dictionary, const String& key, StringType& ...@@ -109,19 +109,19 @@ bool getStringType(const Dictionary& dictionary, const String& key, StringType&
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, String& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, String& value)
{ {
return getStringType(dictionary, key, value); return getStringType(dictionary, key, value);
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, AtomicString& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, AtomicString& value)
{ {
return getStringType(dictionary, key, value); return getStringType(dictionary, key, value);
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, ScriptValue& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, ScriptValue& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -132,7 +132,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri ...@@ -132,7 +132,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri
} }
template<typename NumericType> template<typename NumericType>
bool getNumericType(const Dictionary& dictionary, const String& key, NumericType& value) bool getNumericType(const Dictionary& dictionary, const StringView& key, NumericType& value)
{ {
int32_t int32Value; int32_t int32Value;
if (!DictionaryHelper::get(dictionary, key, int32Value)) if (!DictionaryHelper::get(dictionary, key, int32Value))
...@@ -142,25 +142,25 @@ bool getNumericType(const Dictionary& dictionary, const String& key, NumericType ...@@ -142,25 +142,25 @@ bool getNumericType(const Dictionary& dictionary, const String& key, NumericType
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, short& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, short& value)
{ {
return getNumericType<short>(dictionary, key, value); return getNumericType<short>(dictionary, key, value);
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsigned short& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, unsigned short& value)
{ {
return getNumericType<unsigned short>(dictionary, key, value); return getNumericType<unsigned short>(dictionary, key, value);
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsigned& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, unsigned& value)
{ {
return getNumericType<unsigned>(dictionary, key, value); return getNumericType<unsigned>(dictionary, key, value);
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsigned long& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, unsigned long& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -174,7 +174,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi ...@@ -174,7 +174,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsigned long long& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, unsigned long long& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -188,7 +188,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi ...@@ -188,7 +188,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Member<DOMWindow>& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Member<DOMWindow>& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -201,7 +201,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb ...@@ -201,7 +201,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Member<TrackBase>& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Member<TrackBase>& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -222,7 +222,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb ...@@ -222,7 +222,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
} }
template <> template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Member<EventTarget>& value) bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Member<EventTarget>& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -248,7 +248,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb ...@@ -248,7 +248,7 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Vector<String>& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Vector<String>& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -270,7 +270,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -270,7 +270,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Vector<Vector<String>>& value, ExceptionState& exceptionState) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, Vector<Vector<String>>& value, ExceptionState& exceptionState)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -294,7 +294,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -294,7 +294,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template <> template <>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, ArrayValue& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, ArrayValue& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
...@@ -310,7 +310,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin ...@@ -310,7 +310,7 @@ CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
} }
template<> template<>
CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, DOMUint8Array*& value) CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const StringView& key, DOMUint8Array*& value)
{ {
v8::Local<v8::Value> v8Value; v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value)) if (!dictionary.get(key, v8Value))
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
namespace blink { namespace blink {
template bool DictionaryHelper::get(const Dictionary&, const String& key, Member<Headers>& value); template bool DictionaryHelper::get(const Dictionary&, const StringView& key, Member<Headers>& value);
template bool DictionaryHelper::get(const Dictionary&, const String& key, Member<PasswordCredential>& value); template bool DictionaryHelper::get(const Dictionary&, const StringView& key, Member<PasswordCredential>& value);
} // namespace blink } // namespace blink
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