diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | benchmarks/misc/cbits_benchmark.cpp | 2 | ||||
| -rw-r--r-- | benchmarks/misc/sso_bench.cpp | 3 | ||||
| -rw-r--r-- | benchmarks/misc/string_bench_STC.cpp | 2 | ||||
| -rw-r--r-- | benchmarks/misc/string_bench_STD.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/picobench/picobench_cmap.cpp | 2 | ||||
| -rw-r--r-- | benchmarks/picobench/picobench_csmap.cpp | 2 | ||||
| -rw-r--r-- | benchmarks/plotbench/cdeq_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/plotbench/clist_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/plotbench/cmap_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/plotbench/cpque_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/plotbench/csmap_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/plotbench/cvec_benchmark.cpp | 1 | ||||
| -rw-r--r-- | benchmarks/shootout_hashmaps.cpp | 1 | ||||
| -rw-r--r-- | include/stc/cstr.h | 10 | ||||
| -rw-r--r-- | include/stc/csview.h | 2 | ||||
| -rw-r--r-- | include/stc/utf8.h | 2 | ||||
| -rw-r--r-- | src/utf8code.c | 4 | ||||
| -rw-r--r-- | src/utf8tabs.h | 10 | ||||
| -rw-r--r-- | src/utf8tabs.inc (renamed from src/utf8tabs.c) | 8 | ||||
| -rw-r--r-- | src/utf8tabs.py | 9 |
21 files changed, 38 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0c474fa5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.out
+*.exe
+stuff/*
diff --git a/benchmarks/misc/cbits_benchmark.cpp b/benchmarks/misc/cbits_benchmark.cpp index 50e19a7c..dd709db1 100644 --- a/benchmarks/misc/cbits_benchmark.cpp +++ b/benchmarks/misc/cbits_benchmark.cpp @@ -4,7 +4,7 @@ #include <ctime> // timer enum{ N=1<<22 }; // 4.2 mill. - +#define i_static #include <stc/crandom.h> #define i_type cbits #define i_len N diff --git a/benchmarks/misc/sso_bench.cpp b/benchmarks/misc/sso_bench.cpp index f503ffb0..bcc43ba0 100644 --- a/benchmarks/misc/sso_bench.cpp +++ b/benchmarks/misc/sso_bench.cpp @@ -3,7 +3,10 @@ #include <vector> #include <unordered_set> #include <chrono> +#define i_static #include <stc/crandom.h> +#define i_static +#include <stc/cstr.h> #define i_type stccon #define i_val_str diff --git a/benchmarks/misc/string_bench_STC.cpp b/benchmarks/misc/string_bench_STC.cpp index d5b3a306..2e05dae3 100644 --- a/benchmarks/misc/string_bench_STC.cpp +++ b/benchmarks/misc/string_bench_STC.cpp @@ -4,7 +4,9 @@ #include <iostream> #include <iomanip> #include <chrono> +#define i_static #include <stc/cstr.h> // string +#define i_static #include <stc/csview.h> // string_view #define i_key_str diff --git a/benchmarks/misc/string_bench_STD.cpp b/benchmarks/misc/string_bench_STD.cpp index 595ab632..5f033ca1 100644 --- a/benchmarks/misc/string_bench_STD.cpp +++ b/benchmarks/misc/string_bench_STD.cpp @@ -10,6 +10,7 @@ #include <vector> #include <map> #include <unordered_map> +#define i_static #include <stc/cstr.h> std::vector<std::string> read_file(const char* name) diff --git a/benchmarks/picobench/picobench_cmap.cpp b/benchmarks/picobench/picobench_cmap.cpp index d72ea12f..30170061 100644 --- a/benchmarks/picobench/picobench_cmap.cpp +++ b/benchmarks/picobench/picobench_cmap.cpp @@ -1,4 +1,6 @@ +#define i_static
#include <stc/crandom.h>
+#define i_static
#include <stc/cstr.h>
#include <cmath>
#include <string>
diff --git a/benchmarks/picobench/picobench_csmap.cpp b/benchmarks/picobench/picobench_csmap.cpp index f5235ce1..3f203cc8 100644 --- a/benchmarks/picobench/picobench_csmap.cpp +++ b/benchmarks/picobench/picobench_csmap.cpp @@ -1,5 +1,7 @@ #include <iostream>
+#define i_static
#include <stc/crandom.h>
+#define i_static
#include <stc/cstr.h>
#include <cmath>
#include <string>
diff --git a/benchmarks/plotbench/cdeq_benchmark.cpp b/benchmarks/plotbench/cdeq_benchmark.cpp index b6eebb26..057a50b8 100644 --- a/benchmarks/plotbench/cdeq_benchmark.cpp +++ b/benchmarks/plotbench/cdeq_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#ifdef __cplusplus
diff --git a/benchmarks/plotbench/clist_benchmark.cpp b/benchmarks/plotbench/clist_benchmark.cpp index c82c9506..dfa043f0 100644 --- a/benchmarks/plotbench/clist_benchmark.cpp +++ b/benchmarks/plotbench/clist_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#ifdef __cplusplus
diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index a22aee86..1021ab1c 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#ifdef __cplusplus
diff --git a/benchmarks/plotbench/cpque_benchmark.cpp b/benchmarks/plotbench/cpque_benchmark.cpp index 4a9e830a..b38bed1a 100644 --- a/benchmarks/plotbench/cpque_benchmark.cpp +++ b/benchmarks/plotbench/cpque_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#define i_val float
diff --git a/benchmarks/plotbench/csmap_benchmark.cpp b/benchmarks/plotbench/csmap_benchmark.cpp index baf4c879..778d6894 100644 --- a/benchmarks/plotbench/csmap_benchmark.cpp +++ b/benchmarks/plotbench/csmap_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#ifdef __cplusplus
diff --git a/benchmarks/plotbench/cvec_benchmark.cpp b/benchmarks/plotbench/cvec_benchmark.cpp index 357cfcf0..c23b689a 100644 --- a/benchmarks/plotbench/cvec_benchmark.cpp +++ b/benchmarks/plotbench/cvec_benchmark.cpp @@ -1,5 +1,6 @@ #include <stdio.h>
#include <time.h>
+#define i_static
#include <stc/crandom.h>
#ifdef __cplusplus
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp index 62ba5979..7c23fdb8 100644 --- a/benchmarks/shootout_hashmaps.cpp +++ b/benchmarks/shootout_hashmaps.cpp @@ -1,5 +1,6 @@ #include <stdio.h> #include <time.h> +#define i_static #include <stc/crandom.h> #include <stc/cstr.h> #include "external/khash.h" diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 47dff3cd..c08a51c2 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -170,7 +170,7 @@ STC_INLINE size_t cstr_length(cstr s) STC_INLINE size_t cstr_capacity(cstr s)
{ return cstr_is_long(&s) ? cstr_l_cap(&s) : cstr_s_cap; }
-// utf8 methods defined in/depending on src/utf8utils.c:
+// utf8 methods defined in/depending on src/utf8code.c:
cstr cstr_tolower(const cstr* self);
cstr cstr_toupper(const cstr* self);
void cstr_lowercase(cstr* self);
@@ -251,7 +251,7 @@ STC_INLINE bool cstr_equals_s(cstr s1, cstr s2) { return cstr_cmp(&s1, &s2) == 0; }
STC_INLINE size_t cstr_find(cstr s, const char* search) {
- const char *str = cstr_str(&s), *res = strstr(str, search);
+ const char *str = cstr_str(&s), *res = strstr((char*)str, search);
return res ? res - str : cstr_npos;
}
@@ -259,10 +259,10 @@ STC_INLINE size_t cstr_find_s(cstr s, cstr search) { return cstr_find(s, cstr_str(&search)); }
STC_INLINE bool cstr_contains(cstr s, const char* search)
- { return strstr(cstr_str(&s), search) != NULL; }
+ { return strstr(cstr_data(&s), search) != NULL; }
STC_INLINE bool cstr_contains_s(cstr s, cstr search)
- { return strstr(cstr_str(&s), cstr_str(&search)) != NULL; }
+ { return strstr(cstr_data(&s), cstr_str(&search)) != NULL; }
STC_INLINE bool cstr_starts_with(cstr s, const char* sub) {
const char* str = cstr_str(&s);
@@ -414,7 +414,7 @@ STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) { STC_DEF size_t cstr_find_from(cstr s, const size_t pos, const char* search) {
csview sv = cstr_sv(&s);
if (pos > sv.size) return cstr_npos;
- char* res = strstr(sv.str + pos, search);
+ const char* res = strstr((char*)sv.str + pos, search);
return res ? res - sv.str : cstr_npos;
}
diff --git a/include/stc/csview.h b/include/stc/csview.h index eb79c482..eebcb9b7 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -102,7 +102,7 @@ STC_INLINE csview csview_substr_u8(csview sv, size_t u8pos, size_t u8len) { return sv;
}
-STC_INLINE bool csview_valid_u8(csview sv) // depends on src/utf8utils.c
+STC_INLINE bool csview_valid_u8(csview sv) // depends on src/utf8code.c
{ return utf8_valid_n(sv.str, sv.size); }
diff --git a/include/stc/utf8.h b/include/stc/utf8.h index dffd9f15..67722345 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -25,7 +25,7 @@ int main() #include "ccommon.h"
#include <ctype.h>
-// utf8 methods defined in src/utf8utils.c:
+// utf8 methods defined in src/utf8code.c:
bool utf8_islower(uint32_t c);
bool utf8_isupper(uint32_t c);
bool utf8_isspace(uint32_t c);
diff --git a/src/utf8code.c b/src/utf8code.c index 3b01ae39..c58f78b6 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -1,9 +1,7 @@ #include <ctype.h> #define i_header #include <stc/cstr.h> - -#include "utf8tabs.h" -#include "utf8tabs.c" +#include "utf8tabs.inc" // https://news.ycombinator.com/item?id=15423674 // https://gist.github.com/s4y/344a355f8c1f99c6a4cb2347ec4323cc diff --git a/src/utf8tabs.h b/src/utf8tabs.h deleted file mode 100644 index 95251f75..00000000 --- a/src/utf8tabs.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef utf8tabs_included -#define utf8tabs_included - -#include <stdint.h> -struct CaseFold { uint16_t c0, c1, m1; } ; - -extern struct CaseFold casefold[188]; -extern uint8_t cfold_low[188]; - -#endif diff --git a/src/utf8tabs.c b/src/utf8tabs.inc index eccf0496..84b69eec 100644 --- a/src/utf8tabs.c +++ b/src/utf8tabs.inc @@ -1,6 +1,8 @@ -#include "utf8tabs.h" +#include <stdint.h> -struct CaseFold casefold[] = { +struct CaseFold { uint16_t c0, c1, m1; }; + +static struct CaseFold casefold[] = { {65, 90, 122}, {181, 181, 956}, {192, 214, 246}, {216, 222, 254}, {256, 302, 303}, {306, 310, 311}, {313, 327, 328}, {330, 374, 375}, {376, 376, 255}, {377, 381, 382}, {383, 383, 115}, {385, 385, 595}, {386, 388, 389}, {390, 390, 596}, @@ -46,7 +48,7 @@ struct CaseFold casefold[] = { {42960, 42962, 42963}, {42968, 42970, 42971}, {43888, 43913, 5049}, {65313, 65338, 65370}, }; // 188 -uint8_t cfold_low[] = { +static uint8_t cfold_low[] = { 0, 138, 10, 111, 2, 139, 3, 8, 4, 5, 6, 7, 9, 59, 12, 14, 16, 20, 49, 25, 56, 52, 29, 31, 33, 35, 37, 39, 50, 40, 41, 42, 43, 44, 45, 17, 46, 47, 48, 51, 53, 55, 155, 58, 62, 152, 150, 153, 11, 13, 15, 18, 19, 171, 21, 172, 22, 167, 170, 24, diff --git a/src/utf8tabs.py b/src/utf8tabs.py index 9870e181..c4c48113 100644 --- a/src/utf8tabs.py +++ b/src/utf8tabs.py @@ -83,13 +83,13 @@ def make_casefold(letters): def print_casefold(cfold): - print(''' -struct CaseFold casefold[] = {''') + print('#include <stdint.h>\n') + print('struct CaseFold { uint16_t c0, c1, m1; };\n') + print('static struct CaseFold casefold[] = {\n ', end='') n = 1 s = 5 count = 0 table = [] - print(' ', end='') for x in cfold: d = 2 if abs(x[2]) == 1 else 1 a = x[0] @@ -129,7 +129,7 @@ def print_casefold_low(table): cfold_low = [i for i in range(len(table))] cfold_low.sort(key=lambda i: table[i][2] - (table[i][1] - table[i][0])) - print('uint8_t cfold_low[] = {\n ', end='') + print('static uint8_t cfold_low[] = {\n ', end='') for i in range(len(cfold_low)): print(" %d," % (cfold_low[i]), end='\n ' if (i+1) % 20 == 0 else '') print('\n};') @@ -138,7 +138,6 @@ def print_casefold_low(table): ########### main: if __name__ == "__main__": - print('#include "utf8tabs.h"') cfold = make_casetable() table = print_casefold(cfold) print_casefold_low(table) |
