summaryrefslogtreecommitdiff
path: root/core/upb_string.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2010-07-11 18:53:27 -0700
committerJoshua Haberman <joshua@reverberate.org>2010-07-11 18:53:27 -0700
commit7a6a702792e769366a8852fc90dbea9cfc9e01c0 (patch)
tree3315b7ffaf527f1096aba986a73d346be00a68a1 /core/upb_string.c
parentfcfc37e7d41f87bc9ff5ecfb64e0aebb3457c633 (diff)
Allow static upb_strings.
This can allow strings to reference static data, and reduced the memory footprint of test_def by about 10% (3k).
Diffstat (limited to 'core/upb_string.c')
-rw-r--r--core/upb_string.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/upb_string.c b/core/upb_string.c
index 3563c9e..ca3c669 100644
--- a/core/upb_string.c
+++ b/core/upb_string.c
@@ -61,12 +61,12 @@ void _upb_string_free(upb_string *str) {
}
upb_string *upb_string_tryrecycle(upb_string *str) {
- if(str == NULL || upb_atomic_read(&str->refcount) > 1) {
- return upb_string_new();
- } else {
+ if(str && upb_atomic_read(&str->refcount) == 1) {
str->ptr = NULL;
upb_string_release(str);
return str;
+ } else {
+ return upb_string_new();
}
}
@@ -125,3 +125,9 @@ upb_string *upb_string_asprintf(const char *format, ...) {
va_end(args);
return str;
}
+
+upb_string *upb_strdup(upb_string *s) {
+ upb_string *str = upb_string_new();
+ upb_strcpy(str, s);
+ return str;
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback