Commits

Maciej Fijalkowski committed 6745ed0

small cleanups

  • Participants
  • Parent commits fd1859e
  • Branches json-decoder-speedups

Comments (0)

Files changed (1)

File lib-python/modified-2.7/json/decoder.py

 WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS)
 WHITESPACE_STR = ' \t\n\r'
 
+def is_whitespace(c):
+    return c == ' ' or c == '\t' or c == '\n' or c == '\r'
+
 def JSONObject(s_and_end, encoding, strict, scan_once, object_hook,
-               object_pairs_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+               object_pairs_hook, _w=WHITESPACE.match):
     s, end = s_and_end
     # Use a slice to prevent IndexError from being raised, the following
     # check will raise a more specific ValueError if the string is empty
     nextchar = s[end:end + 1]
     # Normally we expect nextchar == '"'
     if nextchar != '"':
-        if nextchar in _ws:
+        if is_whitespace(nextchar):
             end = _w(s, end).end()
             nextchar = s[end:end + 1]
         # Trivial empty object
         end += 1
 
         try:
-            if s[end] in _ws:
+            if is_whitespace(s[end]):
                 end += 1
-                if s[end] in _ws:
+                if is_whitespace(s[end]):
                     end = _w(s, end + 1).end()
         except IndexError:
             pass
 
         try:
             nextchar = s[end]
-            if nextchar in _ws:
+            if is_whitespace(nextchar):
                 end = _w(s, end + 1).end()
                 nextchar = s[end]
         except IndexError:
 
         try:
             nextchar = s[end]
-            if nextchar in _ws:
+            if is_whitespace(nextchar):
                 end += 1
                 nextchar = s[end]
-                if nextchar in _ws:
+                if is_whitespace(nextchar):
                     end = _w(s, end + 1).end()
                     nextchar = s[end]
         except IndexError:
         pairs = object_hook(pairs)
     return pairs, end
 
-def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match):
     s, end = s_and_end
     values = []
     nextchar = s[end:end + 1]
-    if nextchar in _ws:
+    if is_whitespace(nextchar):
         end = _w(s, end + 1).end()
         nextchar = s[end:end + 1]
     # Look-ahead for trivial empty array
             raise ValueError(errmsg("Expecting object", s, end))
         values.append(value)
         nextchar = s[end:end + 1]
-        if nextchar in _ws:
+        if is_whitespace(nextchar):
             end = _w(s, end + 1).end()
             nextchar = s[end:end + 1]
         end += 1
             raise ValueError(errmsg("Expecting , delimiter", s, end))
 
         try:
-            if s[end] in _ws:
+            if is_whitespace(s[end]):
                 end += 1
-                if s[end] in _ws:
+                if is_whitespace(s[end]):
                     end = _w(s, end + 1).end()
         except IndexError:
             pass