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

Side by Side Diff: base/json/json_parser.cc

Issue 2811053002: Reland of Use base::flat_map for base::Value dictionary storage. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/values.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_parser.h" 5 #include "base/json/json_parser.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); 337 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
338 return nullptr; 338 return nullptr;
339 } 339 }
340 340
341 StackMarker depth_check(&stack_depth_); 341 StackMarker depth_check(&stack_depth_);
342 if (depth_check.IsTooDeep()) { 342 if (depth_check.IsTooDeep()) {
343 ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1); 343 ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1);
344 return nullptr; 344 return nullptr;
345 } 345 }
346 346
347 std::unique_ptr<DictionaryValue> dict(new DictionaryValue); 347 std::vector<Value::DictStorage::value_type> dict_storage;
348 348
349 NextChar(); 349 NextChar();
350 Token token = GetNextToken(); 350 Token token = GetNextToken();
351 while (token != T_OBJECT_END) { 351 while (token != T_OBJECT_END) {
352 if (token != T_STRING) { 352 if (token != T_STRING) {
353 ReportError(JSONReader::JSON_UNQUOTED_DICTIONARY_KEY, 1); 353 ReportError(JSONReader::JSON_UNQUOTED_DICTIONARY_KEY, 1);
354 return nullptr; 354 return nullptr;
355 } 355 }
356 356
357 // First consume the key. 357 // First consume the key.
(...skipping 11 matching lines...) Expand all
369 } 369 }
370 370
371 // The next token is the value. Ownership transfers to |dict|. 371 // The next token is the value. Ownership transfers to |dict|.
372 NextChar(); 372 NextChar();
373 std::unique_ptr<Value> value = ParseNextToken(); 373 std::unique_ptr<Value> value = ParseNextToken();
374 if (!value) { 374 if (!value) {
375 // ReportError from deeper level. 375 // ReportError from deeper level.
376 return nullptr; 376 return nullptr;
377 } 377 }
378 378
379 dict->SetWithoutPathExpansion(key.AsStringPiece(), std::move(value)); 379 dict_storage.emplace_back(key.DestructiveAsString(), std::move(value));
380 380
381 NextChar(); 381 NextChar();
382 token = GetNextToken(); 382 token = GetNextToken();
383 if (token == T_LIST_SEPARATOR) { 383 if (token == T_LIST_SEPARATOR) {
384 NextChar(); 384 NextChar();
385 token = GetNextToken(); 385 token = GetNextToken();
386 if (token == T_OBJECT_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) { 386 if (token == T_OBJECT_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) {
387 ReportError(JSONReader::JSON_TRAILING_COMMA, 1); 387 ReportError(JSONReader::JSON_TRAILING_COMMA, 1);
388 return nullptr; 388 return nullptr;
389 } 389 }
390 } else if (token != T_OBJECT_END) { 390 } else if (token != T_OBJECT_END) {
391 ReportError(JSONReader::JSON_SYNTAX_ERROR, 0); 391 ReportError(JSONReader::JSON_SYNTAX_ERROR, 0);
392 return nullptr; 392 return nullptr;
393 } 393 }
394 } 394 }
395 395
396 return std::move(dict); 396 return MakeUnique<Value>(
397 Value::DictStorage(std::move(dict_storage), KEEP_LAST_OF_DUPES));
397 } 398 }
398 399
399 std::unique_ptr<Value> JSONParser::ConsumeList() { 400 std::unique_ptr<Value> JSONParser::ConsumeList() {
400 if (*pos_ != '[') { 401 if (*pos_ != '[') {
401 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); 402 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
402 return nullptr; 403 return nullptr;
403 } 404 }
404 405
405 StackMarker depth_check(&stack_depth_); 406 StackMarker depth_check(&stack_depth_);
406 if (depth_check.IsTooDeep()) { 407 if (depth_check.IsTooDeep()) {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 const std::string& description) { 830 const std::string& description) {
830 if (line || column) { 831 if (line || column) {
831 return StringPrintf("Line: %i, column: %i, %s", 832 return StringPrintf("Line: %i, column: %i, %s",
832 line, column, description.c_str()); 833 line, column, description.c_str());
833 } 834 }
834 return description; 835 return description;
835 } 836 }
836 837
837 } // namespace internal 838 } // namespace internal
838 } // namespace base 839 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/values.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698