From 619edf5e7d46eea314c3d5194eeaed7bee5635d1 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 31 Mar 2022 17:34:17 -0700 Subject: [PATCH] libobs: Add pointer to obs_data_item name Rather than have to look up the string each time, just add a pointer to the string. Still all stored in the same memory though. --- libobs/obs-data.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libobs/obs-data.c b/libobs/obs-data.c index c6a03e081..f277151c4 100644 --- a/libobs/obs-data.c +++ b/libobs/obs-data.c @@ -30,6 +30,7 @@ struct obs_data_item { volatile long ref; + const char *name; struct obs_data *parent; struct obs_data_item *next; enum obs_data_type type; @@ -295,7 +296,10 @@ static struct obs_data_item *obs_data_item_create(const char *name, item->data_size = size; } - strcpy(get_item_name(item), name); + char *name_ptr = get_item_name(item); + item->name = name_ptr; + + strcpy(name_ptr, name); memcpy(get_item_data(item), data, size); item_data_addref(item); @@ -354,6 +358,7 @@ obs_data_item_ensure_capacity(struct obs_data_item *item) new_item = brealloc(item, new_size); new_item->capacity = new_size; + new_item->name = get_item_name(new_item); obs_data_item_reattach(item, new_item); return new_item; @@ -1671,7 +1676,7 @@ const char *obs_data_item_get_name(obs_data_item_t *item) if (!item) return NULL; - return get_item_name(item); + return item->name; } void obs_data_item_set_string(obs_data_item_t **item, const char *val)