Show More
@@ -68,26 +68,41 b' static int _addpath(PyObject *dirs, PyOb' | |||
|
68 | 68 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
69 | 69 | PyObject *val; |
|
70 | 70 | |
|
71 | /* It's likely that every prefix already has an entry | |
|
72 | in our dict. Try to avoid allocating and | |
|
73 | deallocating a string for each prefix we check. */ | |
|
74 | if (key != NULL) | |
|
75 | ((PyBytesObject *)key)->ob_shash = -1; | |
|
76 | else { | |
|
77 | /* Force Python to not reuse a small shared string. */ | |
|
78 | key = PyBytes_FromStringAndSize(cpath, | |
|
79 | pos < 2 ? 2 : pos); | |
|
71 | if (pos < 2) { | |
|
72 | key = PyBytes_FromStringAndSize(cpath, pos); | |
|
80 | 73 | if (key == NULL) |
|
81 | 74 | goto bail; |
|
75 | } else { | |
|
76 | /* It's likely that every prefix already has an entry | |
|
77 | in our dict. Try to avoid allocating and | |
|
78 | deallocating a string for each prefix we check. */ | |
|
79 | if (key != NULL) | |
|
80 | ((PyBytesObject *)key)->ob_shash = -1; | |
|
81 | else { | |
|
82 | /* We know pos >= 2, so we won't get a small | |
|
83 | * shared string. */ | |
|
84 | key = PyBytes_FromStringAndSize(cpath, pos); | |
|
85 | if (key == NULL) | |
|
86 | goto bail; | |
|
87 | } | |
|
88 | /* Py_SIZE(o) refers to the ob_size member of | |
|
89 | * the struct. Yes, assigning to what looks | |
|
90 | * like a function seems wrong. */ | |
|
91 | Py_SIZE(key) = pos; | |
|
92 | ((PyBytesObject *)key)->ob_sval[pos] = '\0'; | |
|
82 | 93 | } |
|
83 | /* Py_SIZE(o) refers to the ob_size member of the struct. Yes, | |
|
84 | * assigning to what looks like a function seems wrong. */ | |
|
85 | Py_SIZE(key) = pos; | |
|
86 | ((PyBytesObject *)key)->ob_sval[pos] = '\0'; | |
|
87 | 94 | |
|
88 | 95 | val = PyDict_GetItem(dirs, key); |
|
89 | 96 | if (val != NULL) { |
|
90 | 97 | PYLONG_VALUE(val) += 1; |
|
98 | if (pos < 2) { | |
|
99 | /* This was a short string, so we | |
|
100 | * probably got a small shared string | |
|
101 | * we can't mutate on the next loop | |
|
102 | * iteration. Clear it. | |
|
103 | */ | |
|
104 | Py_CLEAR(key); | |
|
105 | } | |
|
91 | 106 | break; |
|
92 | 107 | } |
|
93 | 108 |
General Comments 0
You need to be logged in to leave comments.
Login now