[fix] only strdup when necessary in feature counting functions

This commit is contained in:
Al
2016-01-08 00:46:41 -05:00
parent 31a3a2a3fa
commit 06638d2885

View File

@@ -29,6 +29,9 @@ 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) { bool feature_counts_update_or_add(khash_t(str_double) *features, char *feature, double count, bool copy, bool add) {
khiter_t k; khiter_t k;
k = kh_get(str_double, features, feature);
if (k == kh_end(features)) {
int ret;
char *str; char *str;
if (copy) { if (copy) {
str = strdup(feature); str = strdup(feature);
@@ -36,9 +39,6 @@ bool feature_counts_update_or_add(khash_t(str_double) *features, char *feature,
str = feature; str = feature;
} }
k = kh_get(str_double, features, str);
if (k == kh_end(features)) {
int ret;
k = kh_put(str_double, features, str, &ret); k = kh_put(str_double, features, str, &ret);
if (ret < 0) return false; if (ret < 0) return false;