patch 9.1.0828: string_T struct could be used more often
Problem: string_T struct could be used more often
Solution: Refactor code and make use of string_T struct
for key-value pairs, reformat overlong lines
(John Marriott)
closes: #15975
Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/autocmd.c b/src/autocmd.c
index 00f41bd..330db42 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -707,8 +707,8 @@
;
target.key = 0;
- target.value = (char *)start;
- target.length = (size_t)(p - start);
+ target.value.string = start;
+ target.value.length = (size_t)(p - start);
// special cases:
// BufNewFile and BufRead are searched for ALOT (especially at startup)
@@ -752,7 +752,7 @@
for (i = cache_last_index; cache_tab[i] >= 0; )
{
if ((event_T)event_tab[cache_tab[i]].key == event)
- return (char_u *)event_tab[cache_tab[i]].value;
+ return event_tab[cache_tab[i]].value.string;
if (i == 0)
i = ARRAY_LENGTH(cache_tab) - 1;
@@ -780,7 +780,8 @@
}
}
- return (i == (int)ARRAY_LENGTH(event_tab)) ? (char_u *)"Unknown" : (char_u *)event_tab[i].value;
+ return (i == (int)ARRAY_LENGTH(event_tab)) ? (char_u *)"Unknown" :
+ event_tab[i].value.string;
}
/*
@@ -2880,7 +2881,7 @@
if (i < 0 || i >= (int)ARRAY_LENGTH(event_tab))
return NULL;
- return (char_u *)event_tab[i].value;
+ return event_tab[i].value.string;
}
/*
@@ -2893,7 +2894,7 @@
if (idx < 0 || idx >= (int)ARRAY_LENGTH(event_tab))
return NULL;
- return (char_u *)event_tab[idx].value;
+ return event_tab[idx].value.string;
}
@@ -3365,9 +3366,11 @@
keyvalue_T *entry;
target.key = 0;
- target.value = (char *)name;
- target.length = (int)STRLEN(target.value);
- entry = (keyvalue_T *)bsearch(&target, &event_tab, ARRAY_LENGTH(event_tab), sizeof(event_tab[0]), cmp_keyvalue_value_ni);
+ target.value.string = name;
+ target.value.length = STRLEN(target.value.string);
+ entry = (keyvalue_T *)bsearch(&target, &event_tab,
+ ARRAY_LENGTH(event_tab), sizeof(event_tab[0]),
+ cmp_keyvalue_value_ni);
if (entry == NULL)
{
semsg(_(e_no_such_event_str), name);