projects
/
pspp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4b21e52
)
string-map: Avoid measuring the length of a string twice.
author
Ben Pfaff
<blp@cs.stanford.edu>
Fri, 18 Jan 2019 05:35:05 +0000
(21:35 -0800)
committer
Ben Pfaff
<blp@cs.stanford.edu>
Wed, 23 Jan 2019 04:35:23 +0000
(20:35 -0800)
src/libpspp/string-map.c
patch
|
blob
|
history
diff --git
a/src/libpspp/string-map.c
b/src/libpspp/string-map.c
index edbd39e92488eb0fba985413ccfda9d1350da15c..afa94b135fa0a8a6936f6b79240dd4715c7fc92f 100644
(file)
--- a/
src/libpspp/string-map.c
+++ b/
src/libpspp/string-map.c
@@
-25,6
+25,7
@@
#include "libpspp/string-set.h"
#include "gl/xalloc.h"
#include "libpspp/string-set.h"
#include "gl/xalloc.h"
+#include "gl/xmemdup0.h"
static struct string_map_node *string_map_find_node_with_hash (
const struct string_map *, const char *key, size_t length,
static struct string_map_node *string_map_find_node_with_hash (
const struct string_map *, const char *key, size_t length,
@@
-199,7
+200,8
@@
string_map_insert (struct string_map *map, const char *key, const char *value)
struct string_map_node *node = string_map_find_node_with_hash (map, key,
length, hash);
if (node == NULL)
struct string_map_node *node = string_map_find_node_with_hash (map, key,
length, hash);
if (node == NULL)
- node = string_map_insert__ (map, xstrdup (key), xstrdup (value), hash);
+ node = string_map_insert__ (map, xmemdup0 (key, length), xstrdup (value),
+ hash);
return node;
}
return node;
}
@@
-235,7
+237,8
@@
string_map_replace (struct string_map *map, const char *key, const char *value)
struct string_map_node *node = string_map_find_node_with_hash (map, key,
length, hash);
if (node == NULL)
struct string_map_node *node = string_map_find_node_with_hash (map, key,
length, hash);
if (node == NULL)
- node = string_map_insert__ (map, xstrdup (key), xstrdup (value), hash);
+ node = string_map_insert__ (map, xmemdup0 (key, length),
+ xstrdup (value), hash);
else
string_map_node_set_value (node, value);
return node;
else
string_map_node_set_value (node, value);
return node;