summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/json_schema.py
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 23:19:17 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 23:19:17 +0000
commit2cb0c4539c1352c55b6fc844a9ece58dd3f962ac (patch)
tree0e86d2c44b4c34a7449259cf2a7ce9e26cdbefc7 /tools/json_schema_compiler/json_schema.py
parente35da7489de6f9ce605a5895f47040fa8bbe9613 (diff)
downloadchromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.zip
chromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.tar.gz
chromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.tar.bz2
Improve performance of extension docs generation by 60%.
Review URL: http://codereview.chromium.org/9996002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/json_schema.py')
-rw-r--r--tools/json_schema_compiler/json_schema.py50
1 files changed, 7 insertions, 43 deletions
diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py
index 240a168..f51cece 100644
--- a/tools/json_schema_compiler/json_schema.py
+++ b/tools/json_schema_compiler/json_schema.py
@@ -4,49 +4,12 @@
import copy
import json
+import os.path
+import sys
-def StripJSONComments(stream):
- """Strips //-style comments from a stream of JSON. Allows un-escaped //
- inside string values.
- """
- # Previously we used json_minify to strip comments, but it seems to be pretty
- # slow and does more than we need. This implementation does a lot less work -
- # it just strips comments from the beginning of the '//' delimiter until end
- # of line, but only if we're not inside a string. For example:
- #
- # {"url": "http://www.example.com"}
- #
- # will work properly, as will:
- #
- # {
- # "url": "http://www.example.com" // some comment
- # }
- result = ""
- last_char = None
- inside_string = False
- inside_comment = False
- buf = ""
- for char in stream:
- if inside_comment:
- if char == '\n':
- inside_comment = False
- else:
- continue
- else:
- if char == '/' and not inside_string:
- if last_char == '/':
- inside_comment = True
- last_char = char
- continue
- else:
- if last_char == '/' and not inside_string:
- result += '/'
- if char == '"':
- inside_string = not inside_string
- last_char = char
- result += char
-
- return result
+_script_path = os.path.realpath(__file__)
+sys.path.insert(0, os.path.normpath(_script_path + "/../../"))
+import json_comment_eater
def DeleteNocompileNodes(item):
def HasNocompile(thing):
@@ -69,7 +32,8 @@ def DeleteNocompileNodes(item):
def Load(filename):
with open(filename, 'r') as handle:
- return DeleteNocompileNodes(json.loads(StripJSONComments(handle.read())))
+ return DeleteNocompileNodes(
+ json.loads(json_comment_eater.Nom(handle.read())))
# A dictionary mapping |filename| to the object resulting from loading the JSON