 Chromium Code Reviews
 Chromium Code Reviews Issue 851673003:
  Cleanup: Some simplifications in json_schema_compiler.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix_dart_tests
    
  
    Issue 851673003:
  Cleanup: Some simplifications in json_schema_compiler.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix_dart_tests| Index: tools/json_schema_compiler/util.h | 
| diff --git a/tools/json_schema_compiler/util.h b/tools/json_schema_compiler/util.h | 
| index 228ecedba6b5023a99ec66de5ba5a7abe0c8d506..5fda37516d210e20291e2bd0bd0f43b756b23179 100644 | 
| --- a/tools/json_schema_compiler/util.h | 
| +++ b/tools/json_schema_compiler/util.h | 
| @@ -16,23 +16,45 @@ namespace json_schema_compiler { | 
| namespace util { | 
| +struct ITEMS_ARE_BINARY {}; | 
| +struct ITEMS_ARE_NOT_BINARY {}; | 
| 
not at google - send to devlin
2015/01/13 18:15:13
Mhm ok I'm going to add Jeffrey here to advise on
 
Jeffrey Yasskin
2015/01/13 18:57:08
Function pointers are generally slow to call, alth
 
not at google - send to devlin
2015/01/13 19:39:56
I'm fairly certain a lot more is going on than cal
 
Jeffrey Yasskin
2015/01/13 21:17:21
Nope. :)
 | 
| + | 
| // Creates a new item at |out| from |from|[|index|]. These are used by template | 
| // specializations of |Get(Optional)ArrayFromList|. | 
| -bool GetItemFromList(const base::ListValue& from, int index, int* out); | 
| -bool GetItemFromList(const base::ListValue& from, int index, bool* out); | 
| -bool GetItemFromList(const base::ListValue& from, int index, double* out); | 
| -bool GetItemFromList(const base::ListValue& from, int index, std::string* out); | 
| bool GetItemFromList(const base::ListValue& from, | 
| int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| + int* out); | 
| +bool GetItemFromList(const base::ListValue& from, | 
| + int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| + bool* out); | 
| +bool GetItemFromList(const base::ListValue& from, | 
| + int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| + double* out); | 
| +bool GetItemFromList(const base::ListValue& from, | 
| + int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| + std::string* out); | 
| +bool GetItemFromList(const base::ListValue& from, | 
| + int index, | 
| + ITEMS_ARE_BINARY, | 
| + std::string* out); | 
| +bool GetItemFromList(const base::ListValue& from, | 
| + int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| linked_ptr<base::Value>* out); | 
| bool GetItemFromList(const base::ListValue& from, | 
| int index, | 
| + ITEMS_ARE_NOT_BINARY binary_tag, | 
| linked_ptr<base::DictionaryValue>* out); | 
| // This template is used for types generated by tools/json_schema_compiler. | 
| -template<class T> | 
| +template <class T> | 
| bool GetItemFromList(const base::ListValue& from, | 
| int index, | 
| + ITEMS_ARE_NOT_BINARY /* binary_tag */, | 
| linked_ptr<T>* out) { | 
| const base::DictionaryValue* dict; | 
| if (!from.GetDictionary(index, &dict)) | 
| @@ -46,13 +68,13 @@ bool GetItemFromList(const base::ListValue& from, | 
| // Populates |out| with |list|. Returns false if there is no list at the | 
| // specified key or if the list has anything other than |T|. | 
| -template <class T> | 
| +template <class T, class BINARY_TAG> | 
| bool PopulateArrayFromList( | 
| - const base::ListValue& list, std::vector<T>* out) { | 
| + const base::ListValue& list, BINARY_TAG binary_tag, std::vector<T>* out) { | 
| out->clear(); | 
| T value; | 
| for (size_t i = 0; i < list.GetSize(); ++i) { | 
| - if (!GetItemFromList(list, i, &value)) | 
| + if (!GetItemFromList(list, i, binary_tag, &value)) | 
| return false; | 
| out->push_back(value); | 
| } | 
| @@ -71,20 +93,20 @@ bool PopulateArrayFromDictionary( | 
| if (!from.GetListWithoutPathExpansion(name, &list)) | 
| return false; | 
| - return PopulateArrayFromList(*list, out); | 
| + return PopulateArrayFromList(*list, ITEMS_ARE_NOT_BINARY(), out); | 
| } | 
| // Creates a new vector containing |list| at |out|. Returns | 
| // true on success or if there is nothing at the specified key. Returns false | 
| // if anything other than a list of |T| is at the specified key. | 
| -template <class T> | 
| -bool PopulateOptionalArrayFromList( | 
| - const base::ListValue& list, | 
| - scoped_ptr<std::vector<T> >* out) { | 
| +template <class T, class BINARY_TAG> | 
| +bool PopulateOptionalArrayFromList(const base::ListValue& list, | 
| + BINARY_TAG binary_tag, | 
| + scoped_ptr<std::vector<T>>* out) { | 
| out->reset(new std::vector<T>()); | 
| T value; | 
| for (size_t i = 0; i < list.GetSize(); ++i) { | 
| - if (!GetItemFromList(list, i, &value)) { | 
| + if (!GetItemFromList(list, i, binary_tag, &value)) { | 
| out->reset(); | 
| return false; | 
| } | 
| @@ -114,7 +136,7 @@ bool PopulateOptionalArrayFromDictionary( | 
| list = static_cast<const base::ListValue*>(maybe_list); | 
| } | 
| - return PopulateOptionalArrayFromList(*list, out); | 
| + return PopulateOptionalArrayFromList(*list, ITEMS_ARE_NOT_BINARY(), out); | 
| } | 
| // Appends a Value newly created from |from| to |out|. These used by template |