diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-01 10:58:56 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-02 07:20:25 +0200 |
commit | 122dbd92c96199e417270a66925c38ac0d03ff4e (patch) | |
tree | a8b1651d2b153b84e9ef707de5f5c1f0abf843e2 /src/fundamental/string-util-fundamental.c | |
parent | dissect: if dissecting without udev, don't look for usec timestamp on db record (diff) | |
download | systemd-122dbd92c96199e417270a66925c38ac0d03ff4e.tar.xz systemd-122dbd92c96199e417270a66925c38ac0d03ff4e.zip |
string-util: trivial optimizations for strverscmp_improved()
Diffstat (limited to '')
-rw-r--r-- | src/fundamental/string-util-fundamental.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/fundamental/string-util-fundamental.c b/src/fundamental/string-util-fundamental.c index 9f14597fef..383e390577 100644 --- a/src/fundamental/string-util-fundamental.c +++ b/src/fundamental/string-util-fundamental.c @@ -152,7 +152,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { * Note that except for '~' prefixed segments, a string has more segments is newer. * So, this check must be after the '~' check. */ if (*a == '\0' || *b == '\0') - return strcmp(a, b); + return CMP(*a, *b); /* Handle '-', which separates version and release, e.g 123.4-3.1.fc33.x86_64 */ if (*a == '-' || *b == '-') { @@ -194,9 +194,9 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { /* Find the leading numeric segments. One may be an empty string. So, * numeric segments are always newer than alpha segments. */ - for (aa = a; *aa != '\0' && isdigit(*aa); aa++) + for (aa = a; isdigit(*aa); aa++) ; - for (bb = b; *bb != '\0' && isdigit(*bb); bb++) + for (bb = b; isdigit(*bb); bb++) ; /* 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) { return r; } else { /* Find the leading non-numeric segments. */ - for (aa = a; *aa != '\0' && is_alpha(*aa); aa++) + for (aa = a; is_alpha(*aa); aa++) ; - for (bb = b; *bb != '\0' && is_alpha(*bb); bb++) + for (bb = b; is_alpha(*bb); bb++) ; /* Note that the segments are usually not NUL-terminated. */ |