Commits

Antonio Cuni committed b31803b

remove one more bound check (safely! :))

Comments (0)

Files changed (1)

pypy/module/_fastjson/interp_decoder.py

     def __init__(self, space, s):
         self.space = space
         self.s = s
-        self.ll_chars = llstr(s).chars
-        self.length = len(self.s)
+        # we put a sentinel at the end so that we never have to check for the
+        # "end of string" condition
+        self.ll_chars = llstr(s+'\0').chars
+        self.length = len(s)
         self.pos = 0
         self.last_type = TYPE_UNKNOWN
 
         return self.s[start:end]
 
     def skip_whitespace(self, i):
-        while i < self.length:
+        while True:
             ch = self.ll_chars[i]
             if is_whitespace(ch):
                 i+=1
 
 @unwrap_spec(s=str)
 def loads(space, s):
-    # the '\0' serves as a sentinel, so that we can avoid the bound check
-    s = s + '\0'
     decoder = JSONDecoder(space, s)
     w_res = decoder.decode_any(0)
     i = decoder.skip_whitespace(decoder.pos)
-    if s[i] != '\0':
+    if i < len(s):
         start = i
         end = len(s) - 1
         raise operationerrfmt(space.w_ValueError, "Extra data: char %d - %d", start, end)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.