Skip to content

Commit 563c116

Browse files
committed
only do strncmp for comparisons if the lengths match
1 parent 26a3349 commit 563c116

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

stringdtype/stringdtype/src/umath.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ string_equal_strided_loop(PyArrayMethod_Context *context, char *const data[],
3030
npy_intp out_stride = strides[2];
3131

3232
while (N--) {
33-
size_t len1 = (*in1)->len;
34-
size_t len2 = (*in2)->len;
35-
size_t maxlen;
33+
ss *s1 = *in1;
34+
ss *s2 = *in2;
3635

37-
if (len1 > len2) {
38-
maxlen = len1;
39-
}
40-
else {
41-
maxlen = len2;
42-
}
43-
44-
if (strncmp((*in1)->buf, (*in2)->buf, maxlen) == 0) {
36+
if (s1->len == s2->len && strncmp(s1->buf, s2->buf, s1->len) == 0) {
4537
*out = (npy_bool)1;
4638
}
4739
else {

0 commit comments

Comments
 (0)