summaryrefslogtreecommitdiff
path: root/glib/grefstring.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2018-06-12 14:05:02 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2018-06-12 14:06:25 +0100
commit25012bf96c3ec6ae54dd2f31f1de4cadb671c9fd (patch)
treee8a9a9a6c0a53b79546117215d93295397da2d6b /glib/grefstring.c
parentb606ce30a2aadd7f393777634b5fd3cdd6258f3d (diff)
downloadglib-refcount-box.tar.gz
Add length accessor for GRefStringrefcount-box
Since we store the size of the allocation in the underlying ArcBox, we can get a constant time getter for the length of the string.
Diffstat (limited to 'glib/grefstring.c')
-rw-r--r--glib/grefstring.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/glib/grefstring.c b/glib/grefstring.c
index cc62c8011..9d64a968b 100644
--- a/glib/grefstring.c
+++ b/glib/grefstring.c
@@ -173,3 +173,21 @@ g_ref_string_release (char *str)
g_arc_box_release_full (str, remove_if_interned);
}
+
+/**
+ * g_ref_string_length:
+ * @str: a reference counted string
+ *
+ * Retrieves the length of @str.
+ *
+ * Returns: the length of the given string, in bytes
+ *
+ * Since: 2.58
+ */
+gsize
+g_ref_string_length (char *str)
+{
+ g_return_val_if_fail (str != NULL && *str != '\0', 0);
+
+ return g_arc_box_get_size (str) - 1;
+}