/src/php-src/Zend/zend_smart_string.h
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright © The PHP Group and Contributors. | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to the Modified BSD License that is | |
6 | | | bundled with this package in the file LICENSE, and is available | |
7 | | | through the World Wide Web at <https://www.php.net/license/>. | |
8 | | | | |
9 | | | SPDX-License-Identifier: BSD-3-Clause | |
10 | | +----------------------------------------------------------------------+ |
11 | | | Author: Sascha Schumann <sascha@schumann.cx> | |
12 | | | Xinchen Hui <laruence@php.net> | |
13 | | +----------------------------------------------------------------------+ |
14 | | */ |
15 | | |
16 | | #ifndef PHP_SMART_STRING_H |
17 | | #define PHP_SMART_STRING_H |
18 | | |
19 | | #include "zend_smart_string_public.h" |
20 | | |
21 | | #include <stdlib.h> |
22 | | #include <zend.h> |
23 | | |
24 | | /* wrapper */ |
25 | | |
26 | | #define smart_string_appends_ex(str, src, what) \ |
27 | | smart_string_appendl_ex((str), (src), strlen(src), (what)) |
28 | | #define smart_string_appends(str, src) \ |
29 | 0 | smart_string_appendl((str), (src), strlen(src)) |
30 | | #define smart_string_append_ex(str, src, what) \ |
31 | | smart_string_appendl_ex((str), ((smart_string *)(src))->c, \ |
32 | | ((smart_string *)(src))->len, (what)); |
33 | | #define smart_string_sets(str, src) \ |
34 | | smart_string_setl((str), (src), strlen(src)); |
35 | | |
36 | | #define smart_string_appendc(str, c) \ |
37 | 1.97M | smart_string_appendc_ex((str), (c), 0) |
38 | | #define smart_string_free(s) \ |
39 | 0 | smart_string_free_ex((s), 0) |
40 | | #define smart_string_appendl(str, src, len) \ |
41 | 126k | smart_string_appendl_ex((str), (src), (len), 0) |
42 | | #define smart_string_append(str, src) \ |
43 | | smart_string_append_ex((str), (src), 0) |
44 | | #define smart_string_append_long(str, val) \ |
45 | | smart_string_append_long_ex((str), (val), 0) |
46 | | #define smart_string_append_unsigned(str, val) \ |
47 | | smart_string_append_unsigned_ex((str), (val), 0) |
48 | | |
49 | | ZEND_API void smart_string_append_printf(smart_string *dest, const char *format, ...) |
50 | | ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); |
51 | | |
52 | | ZEND_API void ZEND_FASTCALL _smart_string_alloc_persistent(smart_string *str, size_t len); |
53 | | ZEND_API void ZEND_FASTCALL _smart_string_alloc(smart_string *str, size_t len); |
54 | | |
55 | 2.10M | static zend_always_inline size_t smart_string_alloc(smart_string *str, size_t len, bool persistent) { |
56 | 2.10M | if (UNEXPECTED(!str->c) || UNEXPECTED(len >= str->a - str->len)) { |
57 | 38.8k | if (persistent) { |
58 | 0 | _smart_string_alloc_persistent(str, len); |
59 | 38.8k | } else { |
60 | 38.8k | _smart_string_alloc(str, len); |
61 | 38.8k | } |
62 | 38.8k | } |
63 | 2.10M | return str->len + len; |
64 | 2.10M | } Unexecuted instantiation: main.c:smart_string_alloc Unexecuted instantiation: php_syslog.c:smart_string_alloc Unexecuted instantiation: rfc1867.c:smart_string_alloc spprintf.c:smart_string_alloc Line | Count | Source | 55 | 2.10M | static zend_always_inline size_t smart_string_alloc(smart_string *str, size_t len, bool persistent) { | 56 | 2.10M | if (UNEXPECTED(!str->c) || UNEXPECTED(len >= str->a - str->len)) { | 57 | 38.8k | if (persistent) { | 58 | 0 | _smart_string_alloc_persistent(str, len); | 59 | 38.8k | } else { | 60 | 38.8k | _smart_string_alloc(str, len); | 61 | 38.8k | } | 62 | 38.8k | } | 63 | 2.10M | return str->len + len; | 64 | 2.10M | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_alloc Unexecuted instantiation: zend.c:smart_string_alloc |
65 | | |
66 | 0 | static zend_always_inline void smart_string_free_ex(smart_string *str, bool persistent) { |
67 | 0 | if (str->c) { |
68 | 0 | pefree(str->c, persistent); |
69 | 0 | str->c = NULL; |
70 | 0 | } |
71 | 0 | str->a = str->len = 0; |
72 | 0 | } Unexecuted instantiation: main.c:smart_string_free_ex Unexecuted instantiation: php_syslog.c:smart_string_free_ex Unexecuted instantiation: rfc1867.c:smart_string_free_ex Unexecuted instantiation: spprintf.c:smart_string_free_ex Unexecuted instantiation: zend_smart_str.c:smart_string_free_ex Unexecuted instantiation: zend.c:smart_string_free_ex |
73 | | |
74 | 32.3k | static zend_always_inline void smart_string_0(smart_string *str) { |
75 | 32.3k | if (str->c) { |
76 | 32.3k | str->c[str->len] = '\0'; |
77 | 32.3k | } |
78 | 32.3k | } Unexecuted instantiation: main.c:smart_string_0 Unexecuted instantiation: php_syslog.c:smart_string_0 Unexecuted instantiation: rfc1867.c:smart_string_0 Unexecuted instantiation: spprintf.c:smart_string_0 Unexecuted instantiation: zend_smart_str.c:smart_string_0 Line | Count | Source | 74 | 32.3k | static zend_always_inline void smart_string_0(smart_string *str) { | 75 | 32.3k | if (str->c) { | 76 | 32.3k | str->c[str->len] = '\0'; | 77 | 32.3k | } | 78 | 32.3k | } |
|
79 | | |
80 | 1.97M | static zend_always_inline void smart_string_appendc_ex(smart_string *dest, char ch, bool persistent) { |
81 | 1.97M | dest->len = smart_string_alloc(dest, 1, persistent); |
82 | 1.97M | dest->c[dest->len - 1] = ch; |
83 | 1.97M | } Unexecuted instantiation: main.c:smart_string_appendc_ex Unexecuted instantiation: php_syslog.c:smart_string_appendc_ex Unexecuted instantiation: rfc1867.c:smart_string_appendc_ex spprintf.c:smart_string_appendc_ex Line | Count | Source | 80 | 1.97M | static zend_always_inline void smart_string_appendc_ex(smart_string *dest, char ch, bool persistent) { | 81 | 1.97M | dest->len = smart_string_alloc(dest, 1, persistent); | 82 | 1.97M | dest->c[dest->len - 1] = ch; | 83 | 1.97M | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_appendc_ex Unexecuted instantiation: zend.c:smart_string_appendc_ex |
84 | | |
85 | 126k | static zend_always_inline void smart_string_appendl_ex(smart_string *dest, const char *str, size_t len, bool persistent) { |
86 | 126k | size_t new_len = smart_string_alloc(dest, len, persistent); |
87 | 126k | memcpy(dest->c + dest->len, str, len); |
88 | 126k | dest->len = new_len; |
89 | | |
90 | 126k | } Unexecuted instantiation: main.c:smart_string_appendl_ex Unexecuted instantiation: php_syslog.c:smart_string_appendl_ex Unexecuted instantiation: rfc1867.c:smart_string_appendl_ex spprintf.c:smart_string_appendl_ex Line | Count | Source | 85 | 126k | static zend_always_inline void smart_string_appendl_ex(smart_string *dest, const char *str, size_t len, bool persistent) { | 86 | 126k | size_t new_len = smart_string_alloc(dest, len, persistent); | 87 | 126k | memcpy(dest->c + dest->len, str, len); | 88 | 126k | dest->len = new_len; | 89 | | | 90 | 126k | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_appendl_ex Unexecuted instantiation: zend.c:smart_string_appendl_ex |
91 | | |
92 | 0 | static zend_always_inline void smart_string_append_long_ex(smart_string *dest, zend_long num, bool persistent) { |
93 | 0 | char buf[32]; |
94 | 0 | char *result = zend_print_long_to_buf(buf + sizeof(buf) - 1, num); |
95 | 0 | smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); |
96 | 0 | } Unexecuted instantiation: main.c:smart_string_append_long_ex Unexecuted instantiation: php_syslog.c:smart_string_append_long_ex Unexecuted instantiation: rfc1867.c:smart_string_append_long_ex Unexecuted instantiation: spprintf.c:smart_string_append_long_ex Unexecuted instantiation: zend_smart_str.c:smart_string_append_long_ex Unexecuted instantiation: zend.c:smart_string_append_long_ex |
97 | | |
98 | 0 | static zend_always_inline void smart_string_append_unsigned_ex(smart_string *dest, zend_ulong num, bool persistent) { |
99 | 0 | char buf[32]; |
100 | 0 | char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num); |
101 | 0 | smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); |
102 | 0 | } Unexecuted instantiation: main.c:smart_string_append_unsigned_ex Unexecuted instantiation: php_syslog.c:smart_string_append_unsigned_ex Unexecuted instantiation: rfc1867.c:smart_string_append_unsigned_ex Unexecuted instantiation: spprintf.c:smart_string_append_unsigned_ex Unexecuted instantiation: zend_smart_str.c:smart_string_append_unsigned_ex Unexecuted instantiation: zend.c:smart_string_append_unsigned_ex |
103 | | |
104 | 0 | static zend_always_inline void smart_string_setl(smart_string *dest, char *src, size_t len) { |
105 | 0 | dest->len = len; |
106 | 0 | dest->a = len + 1; |
107 | 0 | dest->c = src; |
108 | 0 | } Unexecuted instantiation: main.c:smart_string_setl Unexecuted instantiation: php_syslog.c:smart_string_setl Unexecuted instantiation: rfc1867.c:smart_string_setl Unexecuted instantiation: spprintf.c:smart_string_setl Unexecuted instantiation: zend_smart_str.c:smart_string_setl Unexecuted instantiation: zend.c:smart_string_setl |
109 | | |
110 | 0 | static zend_always_inline void smart_string_reset(smart_string *str) { |
111 | 0 | str->len = 0; |
112 | 0 | } Unexecuted instantiation: main.c:smart_string_reset Unexecuted instantiation: php_syslog.c:smart_string_reset Unexecuted instantiation: rfc1867.c:smart_string_reset Unexecuted instantiation: spprintf.c:smart_string_reset Unexecuted instantiation: zend_smart_str.c:smart_string_reset Unexecuted instantiation: zend.c:smart_string_reset |
113 | | |
114 | | #endif |