File tree Expand file tree Collapse file tree 4 files changed +21
-15
lines changed Expand file tree Collapse file tree 4 files changed +21
-15
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,6 @@ per-file-ignores = {"__init__.py" = ["F401"]}
31
31
32
32
[tool .meson-python .args ]
33
33
dist = []
34
- setup = [" -Ddebug=true" , " -Doptimization=0 " ]
34
+ setup = [" -Ddebug=true" , " -Doptimization=2 " ]
35
35
compile = []
36
36
install = []
Original file line number Diff line number Diff line change 2
2
3
3
4
4
class StringScalar (str ):
5
- def partition (self , sep ):
6
- ret = super ().partition (sep )
7
- return (str (ret [0 ]), str (ret [1 ]), str (ret [2 ]))
8
-
9
- def rpartition (self , sep ):
10
- ret = super ().rpartition (sep )
11
- return (str (ret [0 ]), str (ret [1 ]), str (ret [2 ]))
5
+ pass
Original file line number Diff line number Diff line change @@ -146,26 +146,35 @@ static PyObject *
146
146
stringdtype_getitem (StringDTypeObject * NPY_UNUSED (descr ), char * * dataptr )
147
147
{
148
148
char * data ;
149
+ size_t len ;
149
150
150
151
if (* dataptr == NULL ) {
151
152
data = "\0" ;
153
+ len = 0 ;
152
154
}
153
155
else {
154
156
data = ((ss * )dataptr )-> buf ;
157
+ len = ((ss * )dataptr )-> len ;
155
158
}
156
159
157
- PyObject * val_obj = PyUnicode_FromString (data );
160
+ PyObject * val_obj = PyUnicode_FromStringAndSize (data , len );
158
161
159
162
if (val_obj == NULL ) {
160
163
return NULL ;
161
164
}
162
165
163
- PyObject * res = PyObject_CallFunctionObjArgs ((PyObject * )StringScalar_Type ,
164
- val_obj , NULL );
165
-
166
- Py_DECREF (val_obj );
167
-
168
- return res ;
166
+ /*
167
+ * In principle we should return a StringScalar instance here, but
168
+ * creating a StringScalar via PyObject_CallFunctionObjArgs has
169
+ * approximately 4 times as much overhead than just returning a str
170
+ * here. This is due to Python overhead as well as copying the string
171
+ * buffer from val_obj to the StringScalar we'd like to return. In
172
+ * principle we could avoid this by making a C function like
173
+ * PyUnicode_FromStringAndSize that fills a StringScalar instead of a
174
+ * str. For now (4-11-23) we are punting on that with the expectation that
175
+ * eventually the scalar type for this dtype will be str.
176
+ */
177
+ return val_obj ;
169
178
}
170
179
171
180
// PyArray_NonzeroFunc
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ PyInit__main(void)
104
104
if (mod == NULL ) {
105
105
goto error ;
106
106
}
107
+
107
108
StringScalar_Type =
108
109
(PyTypeObject * )PyObject_GetAttrString (mod , "StringScalar" );
109
110
Py_DECREF (mod );
@@ -116,7 +117,9 @@ PyInit__main(void)
116
117
goto error ;
117
118
}
118
119
120
+ Py_INCREF ((PyObject * )& StringDType );
119
121
if (PyModule_AddObject (m , "StringDType" , (PyObject * )& StringDType ) < 0 ) {
122
+ Py_DECREF ((PyObject * )& StringDType );
120
123
goto error ;
121
124
}
122
125
You can’t perform that action at this time.
0 commit comments