Debian Codegraph @

pypy/module/operator/tscmp.c

raw symbols SCIP
1 /* Derived from CPython 3.7's operator.c::_tscmp
2 */
3
4 #include <stdlib.h>
5 #include <wchar.h>
6 #include "src/precommondefs.h"
7 #include "tscmp.h"
8
9 int
10 pypy_tscmp(const char *a, const char *b, Signed len_a, Signed len_b)
11 {
12 /* The volatile type declarations make sure that the compiler has no
13 * chance to optimize and fold the code in any way that may change
14 * the timing.
15 */
16 volatile Signed length;
17 volatile const char *left;
18 volatile const char *right;
19 Signed i;
20 volatile char result;
21
22 /* loop count depends on length of b */
23 length = len_b;
24 left = NULL;
25 right = b;
26
27 /* don't use else here to keep the amount of CPU instructions constant,
28 * volatile forces re-evaluation
29 * */
30 if (len_a == length) {
31 left = *((volatile const char**)&a);
32 result = 0;
33 }
34 if (len_a != length) {
35 left = b;
36 result = 1;
37 }
38
39 for (i=0; i < length; i++) {
40 result |= *left++ ^ *right++;
41 }
42
43 return (result == 0);
44 }