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

Unified Diff: chrome/test/base/ui_test_utils.cc

Issue 10035042: Rewrite base::JSONReader to be 35-40% faster, depending on the input string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 8 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: chrome/test/base/ui_test_utils.cc
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index 7bb1acb170975d4b042f8f36d8d664c0a83c7d50..266f422ddc587591a0b8ecc5c938598518fdf6d3 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -241,28 +241,13 @@ bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host,
if (!result)
return true;
- // Wrap |json| in an array before deserializing because valid JSON has an
- // array or an object as the root.
- json.insert(0, "[");
- json.append("]");
-
- scoped_ptr<Value> root_val(
- base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS));
- if (!root_val->IsType(Value::TYPE_LIST)) {
- DLOG(ERROR) << "JSON result is not a list.";
+ base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
+ result->reset(reader.ReadToValue(json));
+ if (!result->get()) {
+ DLOG(ERROR) << reader.GetErrorMessage();
return false;
}
- ListValue* list = static_cast<ListValue*>(root_val.get());
- Value* result_val;
- if (!list || !list->GetSize() ||
- // Remove gives us ownership of the value.
- !list->Remove(0, &result_val)) {
- DLOG(ERROR) << "JSON result list is empty.";
- return false;
- }
-
- result->reset(result_val);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698