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

Unified Diff: src/json-stringifier.cc

Issue 2740073002: [json] use OrderedHashSet for replacer property list. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | test/mjsunit/json.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-stringifier.cc
diff --git a/src/json-stringifier.cc b/src/json-stringifier.cc
index a187fb54bd922dd485e1d8dec929aea50c394d79..f31aedd9a9484d4f955f680b3f6718c5cbf28650 100644
--- a/src/json-stringifier.cc
+++ b/src/json-stringifier.cc
@@ -101,15 +101,6 @@ MaybeHandle<Object> JsonStringifier::Stringify(Handle<Object> object,
return MaybeHandle<Object>();
}
-bool IsInList(Handle<String> key, List<Handle<String> >* list) {
- // TODO(yangguo): This is O(n^2) for n properties in the list. Deal with this
- // if this becomes an issue.
- for (const Handle<String>& existing : *list) {
- if (String::Equals(existing, key)) return true;
- }
- return false;
-}
-
bool JsonStringifier::InitializeReplacer(Handle<Object> replacer) {
DCHECK(property_list_.is_null());
DCHECK(replacer_function_.is_null());
@@ -117,7 +108,7 @@ bool JsonStringifier::InitializeReplacer(Handle<Object> replacer) {
if (is_array.IsNothing()) return false;
if (is_array.FromJust()) {
HandleScope handle_scope(isolate_);
- List<Handle<String> > list;
+ Handle<OrderedHashSet> set = factory()->NewOrderedHashSet();
Handle<Object> length_obj;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, length_obj,
@@ -140,12 +131,12 @@ bool JsonStringifier::InitializeReplacer(Handle<Object> replacer) {
}
}
if (key.is_null()) continue;
- if (!IsInList(key, &list)) list.Add(key);
- }
- property_list_ = factory()->NewUninitializedFixedArray(list.length());
- for (int i = 0; i < list.length(); i++) {
- property_list_->set(i, *list[i]);
+ // Object keys are internalized, so do it here.
+ key = factory()->InternalizeString(key);
+ set = OrderedHashSet::Add(set, key);
}
+ property_list_ = OrderedHashSet::ConvertToKeysArray(
+ set, GetKeysConversion::kKeepNumbers);
property_list_ = handle_scope.CloseAndEscape(property_list_);
} else if (replacer->IsCallable()) {
replacer_function_ = Handle<JSReceiver>::cast(replacer);
« no previous file with comments | « no previous file | test/mjsunit/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698