aboutsummaryrefslogtreecommitdiffstats
path: root/StringUtils.c
diff options
context:
space:
mode:
authorGraham Inggs <ginggs@debian.org>2018-02-05 14:48:53 +0200
committerGraham Inggs <ginggs@debian.org>2018-02-05 14:48:53 +0200
commit0bffedf65c053726a3a09be93c5eabfc113550fc (patch)
tree8c14970f1890c710df6f72aaa85781d62cee11e5 /StringUtils.c
parentba3d665468e9752a81a50bb2df7639950e0a3c77 (diff)
parent2ee50d030178cede83eb9d0005fbc19f819d30fe (diff)
downloaddebian_htop-0bffedf65c053726a3a09be93c5eabfc113550fc.tar.gz
debian_htop-0bffedf65c053726a3a09be93c5eabfc113550fc.tar.bz2
debian_htop-0bffedf65c053726a3a09be93c5eabfc113550fc.zip
Merge tag 'upstream/2.1.0'
Upstream version 2.1.0
Diffstat (limited to 'StringUtils.c')
-rw-r--r--StringUtils.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/StringUtils.c b/StringUtils.c
index b53f5ee..0578cde 100644
--- a/StringUtils.c
+++ b/StringUtils.c
@@ -17,10 +17,15 @@ in the source distribution for its full text.
/*{
#include <stdio.h>
-#define String_startsWith(s, match) (strstr((s), (match)) == (s))
+#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0)
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
}*/
+/*
+ * String_startsWith gives better performance if strlen(match) can be computed
+ * at compile time (e.g. when they are immutable string literals). :)
+ */
+
char* String_cat(const char* s1, const char* s2) {
int l1 = strlen(s1);
int l2 = strlen(s2);
@@ -88,6 +93,9 @@ char** String_split(const char* s, char sep, int* n) {
}
void String_freeArray(char** s) {
+ if (!s) {
+ return;
+ }
for (int i = 0; s[i] != NULL; i++) {
free(s[i]);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy