Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1024)

Unified Diff: third_party/WebKit/Source/platform/JSONValues.cpp

Issue 2204383003: Make blink::JSONValue (and subclasses) use unique_ptr rather than RefPtrs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/JSONValues.cpp
diff --git a/third_party/WebKit/Source/platform/JSONValues.cpp b/third_party/WebKit/Source/platform/JSONValues.cpp
index 86f642cf6b77490ea7cd5a98e870cabbd5a0986d..65e645136670769334ef0cf076c1ac1dfaa0357d 100644
--- a/third_party/WebKit/Source/platform/JSONValues.cpp
+++ b/third_party/WebKit/Source/platform/JSONValues.cpp
@@ -263,24 +263,24 @@ void JSONObject::setString(const String& name, const String& value)
setValue(name, JSONString::create(value));
}
-void JSONObject::setValue(const String& name, PassRefPtr<JSONValue> value)
+void JSONObject::setValue(const String& name, std::unique_ptr<JSONValue> value)
{
ASSERT(value);
- if (m_data.set(name, value).isNewEntry)
+ if (m_data.set(name, std::move(value)).isNewEntry)
m_order.append(name);
}
-void JSONObject::setObject(const String& name, PassRefPtr<JSONObject> value)
+void JSONObject::setObject(const String& name, std::unique_ptr<JSONObject> value)
{
ASSERT(value);
- if (m_data.set(name, value).isNewEntry)
+ if (m_data.set(name, std::move(value)).isNewEntry)
m_order.append(name);
}
-void JSONObject::setArray(const String& name, PassRefPtr<JSONArray> value)
+void JSONObject::setArray(const String& name, std::unique_ptr<JSONArray> value)
{
ASSERT(value);
- if (m_data.set(name, value).isNewEntry)
+ if (m_data.set(name, std::move(value)).isNewEntry)
m_order.append(name);
}
@@ -296,7 +296,7 @@ JSONObject::const_iterator JSONObject::find(const String& name) const
bool JSONObject::getBoolean(const String& name, bool* output) const
{
- RefPtr<JSONValue> value = get(name);
+ JSONValue* value = get(name);
if (!value)
return false;
return value->asBoolean(output);
@@ -304,28 +304,28 @@ bool JSONObject::getBoolean(const String& name, bool* output) const
bool JSONObject::getString(const String& name, String* output) const
{
- RefPtr<JSONValue> value = get(name);
+ JSONValue* value = get(name);
if (!value)
return false;
return value->asString(output);
}
-PassRefPtr<JSONObject> JSONObject::getObject(const String& name) const
+JSONObject* JSONObject::getObject(const String& name) const
{
return JSONObject::cast(get(name));
}
-PassRefPtr<JSONArray> JSONObject::getArray(const String& name) const
+JSONArray* JSONObject::getArray(const String& name) const
{
return JSONArray::cast(get(name));
}
-PassRefPtr<JSONValue> JSONObject::get(const String& name) const
+JSONValue* JSONObject::get(const String& name) const
{
Dictionary::const_iterator it = m_data.find(name);
if (it == m_data.end())
return nullptr;
- return it->value;
+ return it->value.get();
}
bool JSONObject::booleanProperty(const String& name, bool defaultValue) const
@@ -392,22 +392,25 @@ JSONArray::~JSONArray()
void JSONArray::writeJSON(StringBuilder* output) const
{
+ size_t valuesCount = m_data.size();
output->append('[');
- for (Vector<RefPtr<JSONValue>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
- if (it != m_data.begin())
+ for (size_t i = 0; i < valuesCount; ++i) {
+ if (i > 0)
output->append(',');
- (*it)->writeJSON(output);
+ get(i)->writeJSON(output);
}
output->append(']');
}
void JSONArray::prettyWriteJSONInternal(StringBuilder* output, int depth) const
{
+ size_t valuesCount = m_data.size();
output->append('[');
bool lastInsertedNewLine = false;
- for (Vector<RefPtr<JSONValue>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
- bool insertNewLine = (*it)->getType() == JSONValue::TypeObject || (*it)->getType() == JSONValue::TypeArray || (*it)->getType() == JSONValue::TypeString;
- if (it == m_data.begin()) {
+ for (size_t i = 0; i < valuesCount; ++i) {
+ JSONValue* value = get(i);
+ bool insertNewLine = value->getType() == JSONValue::TypeObject || value->getType() == JSONValue::TypeArray || value->getType() == JSONValue::TypeString;
+ if (i == 0) {
if (insertNewLine) {
output->append('\n');
writeIndent(depth + 1, output);
@@ -421,7 +424,7 @@ void JSONArray::prettyWriteJSONInternal(StringBuilder* output, int depth) const
output->append(' ');
}
}
- (*it)->prettyWriteJSONInternal(output, depth + 1);
+ value->prettyWriteJSONInternal(output, depth + 1);
lastInsertedNewLine = insertNewLine;
}
if (lastInsertedNewLine) {
@@ -457,28 +460,28 @@ void JSONArray::pushString(const String& value)
m_data.append(JSONString::create(value));
}
-void JSONArray::pushValue(PassRefPtr<JSONValue> value)
+void JSONArray::pushValue(std::unique_ptr<JSONValue> value)
{
ASSERT(value);
- m_data.append(value);
+ m_data.append(std::move(value));
}
-void JSONArray::pushObject(PassRefPtr<JSONObject> value)
+void JSONArray::pushObject(std::unique_ptr<JSONObject> value)
{
ASSERT(value);
- m_data.append(value);
+ m_data.append(std::move(value));
}
-void JSONArray::pushArray(PassRefPtr<JSONArray> value)
+void JSONArray::pushArray(std::unique_ptr<JSONArray> value)
{
ASSERT(value);
- m_data.append(value);
+ m_data.append(std::move(value));
}
-PassRefPtr<JSONValue> JSONArray::get(size_t index)
+JSONValue* JSONArray::get(size_t index) const
{
ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
- return m_data[index];
+ return m_data[index].get();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698