summaryrefslogtreecommitdiff
path: root/src/string_vec.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-11-19 17:55:24 +0000
committerPhil Jones <philj56@gmail.com>2022-11-19 18:39:08 +0000
commit52be46abfca9a9b458d7455e891c937437b1356e (patch)
tree428407d2ad26f33ca8ca823bcb2dc1f84bda6804 /src/string_vec.c
parent9ceceeb59a95919e5fe09338dc27e4fac0b5aa24 (diff)
Cleanup some potentially flaky logic.
Some of the string vec code was still assuming that it was just a list of `char *`s, rather than `struct scored_string`s. Correcting that makes future changes a little less error prone, and allows significantly simpler history sorting for tofi-run.
Diffstat (limited to 'src/string_vec.c')
-rw-r--r--src/string_vec.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/string_vec.c b/src/string_vec.c
index a30a570..4607727 100644
--- a/src/string_vec.c
+++ b/src/string_vec.c
@@ -11,23 +11,19 @@
static int cmpstringp(const void *restrict a, const void *restrict b)
{
- /*
- * For qsort we receive pointers to the array elements (which are
- * pointers to char), so convert and dereference them for comparison.
- */
- const char *restrict str1 = *(const char **)a;
- const char *restrict str2 = *(const char **)b;
+ struct scored_string *restrict str1 = (struct scored_string *)a;
+ struct scored_string *restrict str2 = (struct scored_string *)b;
/*
* Ensure any NULL strings are shoved to the end.
*/
- if (str1 == NULL) {
+ if (str1->string == NULL) {
return 1;
}
- if (str2 == NULL) {
+ if (str2->string == NULL) {
return -1;
}
- return strcmp(str1, str2);
+ return strcmp(str1->string, str2->string);
}
static int cmpscorep(const void *restrict a, const void *restrict b)
@@ -109,7 +105,7 @@ void string_vec_uniq(struct string_vec *restrict vec)
vec->count = count;
}
-char **string_vec_find(struct string_vec *restrict vec, const char * str)
+struct scored_string *string_vec_find(struct string_vec *restrict vec, const char * str)
{
return bsearch(&str, vec->buf, vec->count, sizeof(vec->buf[0]), cmpstringp);
}