dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 9 / 0 / 9
Functions: 100.0% 4 / 0 / 4
Branches: 100.0% 4 / 0 / 4

src/util/intern.h
Line Branch Exec Source
1 #ifndef UTIL_INTERN_H
2 #define UTIL_INTERN_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <string.h>
7 #include "macros.h"
8 #include "string-view.h"
9
10 const void *mem_intern(const void *data, size_t len) NONNULL_ARGS_AND_RETURN WARN_UNUSED_RESULT;
11 bool mem_is_intern(const void *data, size_t len) WARN_UNUSED_RESULT;
12 void free_interned_strings(void);
13
14 2377 static inline const char *str_intern(const char *str)
15 {
16 2377 return mem_intern(str, strlen(str));
17 }
18
19 11 static inline StringView strview_intern(const char *str)
20 {
21 11 size_t len = strlen(str);
22 11 return string_view(mem_intern(str, len), len);
23 }
24
25 515 static inline bool str_is_intern(const char *str)
26 {
27
4/4
✓ Branch 2 → 3 taken 514 times.
✓ Branch 2 → 6 taken 1 time.
✓ Branch 4 → 5 taken 257 times.
✓ Branch 4 → 6 taken 257 times.
515 return str && mem_is_intern(str, strlen(str));
28 }
29
30 // Test 2 interned strings for equality, via pointer equality. This
31 // function exists purely to "self-document" the places in the codebase
32 // where pointer equality is used as a substitute for streq(). Note
33 // that particular attention should be given to the special case in
34 // encoding_from_type() and buffer_set_encoding(), when making changes
35 // here.
36 2385 static inline bool interned_strings_equal(const char *a, const char *b)
37 {
38 2385 return a == b;
39 }
40
41 #endif
42