Skip to content

Commit 122dbd9

Browse files
committed
string-util: trivial optimizations for strverscmp_improved()
1 parent 3fe398c commit 122dbd9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/fundamental/string-util-fundamental.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
152152
* Note that except for '~' prefixed segments, a string has more segments is newer.
153153
* So, this check must be after the '~' check. */
154154
if (*a == '\0' || *b == '\0')
155-
return strcmp(a, b);
155+
return CMP(*a, *b);
156156

157157
/* Handle '-', which separates version and release, e.g 123.4-3.1.fc33.x86_64 */
158158
if (*a == '-' || *b == '-') {
@@ -194,9 +194,9 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
194194

195195
/* Find the leading numeric segments. One may be an empty string. So,
196196
* numeric segments are always newer than alpha segments. */
197-
for (aa = a; *aa != '\0' && isdigit(*aa); aa++)
197+
for (aa = a; isdigit(*aa); aa++)
198198
;
199-
for (bb = b; *bb != '\0' && isdigit(*bb); bb++)
199+
for (bb = b; isdigit(*bb); bb++)
200200
;
201201

202202
/* To compare numeric segments without parsing their values, first compare the
@@ -211,9 +211,9 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
211211
return r;
212212
} else {
213213
/* Find the leading non-numeric segments. */
214-
for (aa = a; *aa != '\0' && is_alpha(*aa); aa++)
214+
for (aa = a; is_alpha(*aa); aa++)
215215
;
216-
for (bb = b; *bb != '\0' && is_alpha(*bb); bb++)
216+
for (bb = b; is_alpha(*bb); bb++)
217217
;
218218

219219
/* Note that the segments are usually not NUL-terminated. */

0 commit comments

Comments
 (0)