Skip to content

Commit d02734f

Browse files
committed
Loop invariant code motion
1 parent 1c56a83 commit d02734f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

ext/standard/strnatcmp.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,26 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len
9292
char const *aend = a + a_len,
9393
*bend = b + b_len;
9494
int fractional, result;
95-
short leading = 1;
9695

9796
if (a_len == 0 || b_len == 0) {
9897
return (a_len == b_len ? 0 : (a_len > b_len ? 1 : -1));
9998
}
10099

101100
ap = a;
102101
bp = b;
103-
while (1) {
104-
ca = *ap; cb = *bp;
105102

106-
/* skip over leading zeros */
107-
while (leading && ca == '0' && (ap+1 < aend) && isdigit((int)(unsigned char)*(ap+1))) {
108-
ca = *++ap;
109-
}
103+
ca = *ap; cb = *bp;
110104

111-
while (leading && cb == '0' && (bp+1 < bend) && isdigit((int)(unsigned char)*(bp+1))) {
112-
cb = *++bp;
113-
}
105+
/* skip over leading zeros */
106+
while (ca == '0' && (ap+1 < aend) && isdigit((int)(unsigned char)*(ap+1))) {
107+
ca = *++ap;
108+
}
109+
110+
while (cb == '0' && (bp+1 < bend) && isdigit((int)(unsigned char)*(bp+1))) {
111+
cb = *++bp;
112+
}
114113

115-
leading = 0;
114+
while (1) {
116115

117116
/* Skip consecutive whitespace */
118117
while (isspace((int)(unsigned char)ca)) {
@@ -166,6 +165,8 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len
166165
return -1;
167166
else if (bp >= bend)
168167
return 1;
168+
169+
ca = *ap; cb = *bp;
169170
}
170171
}
171172
/* }}} */

0 commit comments

Comments
 (0)