From 06638d2885b439467524624d9d05abbc804fc570 Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 8 Jan 2016 00:46:41 -0500 Subject: [PATCH] [fix] only strdup when necessary in feature counting functions --- src/features.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/features.c b/src/features.c index 0036ad27..198ee278 100644 --- a/src/features.c +++ b/src/features.c @@ -29,16 +29,16 @@ void feature_array_add_printf(cstring_array *features, char *format, ...) { bool feature_counts_update_or_add(khash_t(str_double) *features, char *feature, double count, bool copy, bool add) { khiter_t k; - char *str; - if (copy) { - str = strdup(feature); - } else { - str = feature; - } - - k = kh_get(str_double, features, str); + k = kh_get(str_double, features, feature); if (k == kh_end(features)) { int ret; + char *str; + if (copy) { + str = strdup(feature); + } else { + str = feature; + } + k = kh_put(str_double, features, str, &ret); if (ret < 0) return false;