##// END OF EJS Templates
encoding: avoid quadratic time complexity when json-encoding non-UTF8 strings...
Arseniy Alekseyev -
r51214:95acba2c default
parent child Browse files
Show More
@@ -657,7 +657,7 b' def toutf8b(s):'
657 657 pass
658 658
659 659 s = pycompat.bytestr(s)
660 r = b""
660 r = bytearray()
661 661 pos = 0
662 662 l = len(s)
663 663 while pos < l:
@@ -673,7 +673,7 b' def toutf8b(s):'
673 673 c = unichr(0xDC00 + ord(s[pos])).encode('utf-8', _utf8strict)
674 674 pos += 1
675 675 r += c
676 return r
676 return bytes(r)
677 677
678 678
679 679 def fromutf8b(s):
@@ -712,7 +712,7 b' def fromutf8b(s):'
712 712 # helper again to walk the string without "decoding" it.
713 713
714 714 s = pycompat.bytestr(s)
715 r = b""
715 r = bytearray()
716 716 pos = 0
717 717 l = len(s)
718 718 while pos < l:
@@ -722,4 +722,4 b' def fromutf8b(s):'
722 722 if b"\xed\xb0\x80" <= c <= b"\xed\xb3\xbf":
723 723 c = pycompat.bytechr(ord(c.decode("utf-8", _utf8strict)) & 0xFF)
724 724 r += c
725 return r
725 return bytes(r)
General Comments 0
You need to be logged in to leave comments. Login now