Skip to content

Commit 4de72c5

Browse files
committed
uuid: Use memcmp instead of strncmp
1 parent 417465e commit 4de72c5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

uuid.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import functools
22
import uuid
33

44
from libc.stdint cimport uint8_t, int8_t
5-
from libc.string cimport memcpy, strncmp
5+
from libc.string cimport memcpy, memcmp
66

77

88
# A more efficient UUID type implementation
@@ -184,42 +184,42 @@ cdef class UUID(__UUIDReplaceMe):
184184

185185
def __eq__(self, other):
186186
if type(other) is UUID:
187-
return strncmp(self._data, (<UUID>other)._data, 16) == 0
187+
return memcmp(self._data, (<UUID>other)._data, 16) == 0
188188
if isinstance(other, std_UUID):
189189
return self.int == other.int
190190
return NotImplemented
191191

192192
def __ne__(self, other):
193193
if type(other) is UUID:
194-
return strncmp(self._data, (<UUID>other)._data, 16) != 0
194+
return memcmp(self._data, (<UUID>other)._data, 16) != 0
195195
if isinstance(other, std_UUID):
196196
return self.int != other.int
197197
return NotImplemented
198198

199199
def __lt__(self, other):
200200
if type(other) is UUID:
201-
return strncmp(self._data, (<UUID>other)._data, 16) < 0
201+
return memcmp(self._data, (<UUID>other)._data, 16) < 0
202202
if isinstance(other, std_UUID):
203203
return self.int < other.int
204204
return NotImplemented
205205

206206
def __gt__(self, other):
207207
if type(other) is UUID:
208-
return strncmp(self._data, (<UUID>other)._data, 16) > 0
208+
return memcmp(self._data, (<UUID>other)._data, 16) > 0
209209
if isinstance(other, std_UUID):
210210
return self.int > other.int
211211
return NotImplemented
212212

213213
def __le__(self, other):
214214
if type(other) is UUID:
215-
return strncmp(self._data, (<UUID>other)._data, 16) <= 0
215+
return memcmp(self._data, (<UUID>other)._data, 16) <= 0
216216
if isinstance(other, std_UUID):
217217
return self.int <= other.int
218218
return NotImplemented
219219

220220
def __ge__(self, other):
221221
if type(other) is UUID:
222-
return strncmp(self._data, (<UUID>other)._data, 16) >= 0
222+
return memcmp(self._data, (<UUID>other)._data, 16) >= 0
223223
if isinstance(other, std_UUID):
224224
return self.int >= other.int
225225
return NotImplemented

0 commit comments

Comments
 (0)