Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc203955

Browse files
authored
gh-124502: Optimize unicode_eq() (#125105)
1 parente99f159 commitc203955

File tree

1 file changed

+12
-7
lines changed
  • Objects/stringlib

1 file changed

+12
-7
lines changed

‎Objects/stringlib/eq.h‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
* unicode_eq() is called when the hash of two unicode objects is equal.
55
*/
66
Py_LOCAL_INLINE(int)
7-
unicode_eq(PyObject*a,PyObject*b)
7+
unicode_eq(PyObject*str1,PyObject*str2)
88
{
9-
if (PyUnicode_GET_LENGTH(a)!=PyUnicode_GET_LENGTH(b))
9+
Py_ssize_tlen=PyUnicode_GET_LENGTH(str1);
10+
if (PyUnicode_GET_LENGTH(str2)!=len) {
1011
return0;
11-
if (PyUnicode_GET_LENGTH(a)==0)
12-
return1;
13-
if (PyUnicode_KIND(a)!=PyUnicode_KIND(b))
12+
}
13+
14+
intkind=PyUnicode_KIND(str1);
15+
if (PyUnicode_KIND(str2)!=kind) {
1416
return0;
15-
returnmemcmp(PyUnicode_1BYTE_DATA(a),PyUnicode_1BYTE_DATA(b),
16-
PyUnicode_GET_LENGTH(a)*PyUnicode_KIND(a))==0;
17+
}
18+
19+
constvoid*data1=PyUnicode_DATA(str1);
20+
constvoid*data2=PyUnicode_DATA(str2);
21+
return (memcmp(data1,data2,len*kind)==0);
1722
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp