aboutsummaryrefslogtreecommitdiffstats
path: root/epan/value_string.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2010-04-27 10:32:34 +0000
committerAnders Broman <anders.broman@ericsson.com>2010-04-27 10:32:34 +0000
commitfab55e4772d878cf191a44363a3db53ec2b76d3b (patch)
treea04a10ab0ad995f93796651efe5d0ed72f3bd1ce /epan/value_string.c
parent13cfe2964f14854076479a6d91c2732b277335ec (diff)
From Jakub Zawadzki:
Itroduce value_string_ext for faster value matching in value_strings. svn path=/trunk/; revision=32574
Diffstat (limited to 'epan/value_string.c')
-rw-r--r--epan/value_string.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/epan/value_string.c b/epan/value_string.c
index 0e43750c71..44b06478c5 100644
--- a/epan/value_string.c
+++ b/epan/value_string.c
@@ -49,6 +49,19 @@ val_to_str(const guint32 val, const value_string *vs, const char *fmt) {
return ep_strdup_printf(fmt, val);
}
+const gchar*
+val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt) {
+ const gchar *ret;
+
+ g_assert(fmt != NULL);
+
+ ret = match_strval_ext(val, vs);
+ if (ret != NULL)
+ return ret;
+
+ return ep_strdup_printf(fmt, val);
+}
+
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr on a match.
Returns 'unknown_str', on failure. */
@@ -65,6 +78,19 @@ val_to_str_const(const guint32 val, const value_string *vs, const char *unknown_
return unknown_str;
}
+const gchar*
+val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str) {
+ const gchar *ret;
+
+ g_assert(unknown_str != NULL);
+
+ ret = match_strval_ext(val, vs);
+ if (ret != NULL)
+ return ret;
+
+ return unknown_str;
+}
+
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr, and sets "*idx" to the index in
that table, on a match, and returns NULL, and sets "*idx" to -1,
@@ -94,6 +120,40 @@ match_strval(const guint32 val, const value_string *vs) {
return match_strval_idx(val, vs, &ignore_me);
}
+const gchar*
+match_strval_ext(const guint32 val, const value_string_ext *vs) {
+ guint low, idx, max;
+ guint32 item;
+ if(vs) {
+ switch(vs->match_type){
+ case VS_DEFAULT:
+ /* XXX: reinit? */
+ case VS_SEARCH:
+ return match_strval(val, vs->vals);
+ case VS_INDEX:
+ return (val < vs->length) ? vs->vals[val].strptr : NULL;
+ case VS_BIN_TREE:
+ for (low = 0, max = vs->length; low < max; ) {
+ idx = (low + max) / 2;
+ item = vs->vals[idx].value;
+
+ if (val < item)
+ max = idx;
+ else if (val > item)
+ low = idx + 1;
+ else
+ return vs->vals[idx].strptr;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+ }
+ return NULL;
+}
+
+
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr on a match.
Formats val with fmt, and returns the resulting string, on failure. */