dte test coverage


Directory: ./
File: src/util/intern.h
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 3 3 100.0%
Branches: 0 0 -%

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;
11 void free_interned_strings(void);
12
13 1932 static inline const char *str_intern(const char *str)
14 {
15 1932 return mem_intern(str, strlen(str));
16 }
17
18 8 static inline StringView strview_intern(const char *str)
19 {
20 8 size_t len = strlen(str);
21 8 return string_view(mem_intern(str, len), len);
22 }
23
24 // Test 2 interned strings for equality, via pointer equality. This
25 // function exists purely to "self-document" the places in the codebase
26 // where pointer equality is used as a substitute for streq(). Note
27 // that particular attention should be given to the special case in
28 // encoding_from_type() and buffer_set_encoding(), when making changes
29 // here.
30 2351 static inline bool interned_strings_equal(const char *a, const char *b)
31 {
32 2351 return a == b;
33 }
34
35 #endif
36