Skip to content

Commit c8a0d2f

Browse files
committed
Intern static string
Use float constructors instead of magic code for float constants
1 parent 8e49973 commit c8a0d2f

2 files changed

Lines changed: 2 additions & 12 deletions

File tree

Lib/json/decoder.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414

1515
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
1616

17-
18-
def _floatconstants():
19-
import struct
20-
import sys
21-
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
22-
if sys.byteorder != 'big':
23-
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
24-
nan, inf = struct.unpack('dd', _BYTES)
25-
return nan, inf, -inf
26-
27-
NaN, PosInf, NegInf = _floatconstants()
17+
NaN, PosInf, NegInf = float('nan'), float('inf'), float('-inf')
2818

2919

3020
def linecol(doc, pos):

Modules/_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ join_list_unicode(PyObject *lst)
215215
ustr = PyUnicode_FromUnicode(&c, 0);
216216
}
217217
if (joinstr == NULL) {
218-
joinstr = PyString_FromString("join");
218+
joinstr = PyString_InternFromString("join");
219219
}
220220
if (joinstr == NULL || ustr == NULL) {
221221
return NULL;

0 commit comments

Comments
 (0)