summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLloyd Hilaiel <lloyd@hilaiel.com>2011-04-22 15:47:44 -0600
committerLloyd Hilaiel <lloyd@hilaiel.com>2011-04-22 15:47:44 -0600
commit86f5093024d434eb989c4d6c7ad657a31f5f4bf1 (patch)
treef734163b55a78c41ca157cc90096fe0db3152737 /src
parentb53a6cb3ee91d2a7765bff88e41089ce17ec7b4a (diff)
downloadyajl-86f5093024d434eb989c4d6c7ad657a31f5f4bf1.tar.gz
remove a useless level of indirection for strings
Diffstat (limited to 'src')
-rw-r--r--src/api/yajl_tree.h12
-rw-r--r--src/yajl_tree.c18
2 files changed, 8 insertions, 22 deletions
diff --git a/src/api/yajl_tree.h b/src/api/yajl_tree.h
index f7147b6..0627249 100644
--- a/src/api/yajl_tree.h
+++ b/src/api/yajl_tree.h
@@ -36,14 +36,6 @@
struct yajl_value_s;
typedef struct yajl_value_s yajl_value_t;
-/** Structure describing a JSON string. */
-struct yajl_value_string_s
-{
- /** Null terminated string. */
- char *value;
-};
-typedef struct yajl_value_string_s yajl_value_string_t;
-
#define YAJL_NUMBER_INT_VALID 0x01
#define YAJL_NUMBER_DOUBLE_VALID 0x02
/** Structure describing a JSON number. */
@@ -119,7 +111,7 @@ struct yajl_value_s
* members. */
union
{
- yajl_value_string_t string;
+ char * string;
yajl_value_number_t number;
yajl_value_object_t object;
yajl_value_array_t array;
@@ -223,7 +215,7 @@ YAJL_API yajl_value_t * yajl_tree_get(yajl_value_t * parent,
* Returns a pointer to a yajl_value_string_t or NULL if the value is not a
* string.
*/
-#define YAJL_TO_STRING(v) (YAJL_IS_STRING(v) ? (v)->data.string.value : NULL)
+#define YAJL_TO_STRING(v) (YAJL_IS_STRING(v) ? (v)->data.string : NULL)
/**
* Convert value to number.
diff --git a/src/yajl_tree.c b/src/yajl_tree.c
index bdfb632..409029c 100644
--- a/src/yajl_tree.c
+++ b/src/yajl_tree.c
@@ -23,8 +23,6 @@
#include "api/yajl_tree.h"
#include "api/yajl_parse.h"
-#define YAJL_TO_STRING2(v) (YAJL_IS_STRING(v) ? &(v)->data.string : NULL)
-
#define STATUS_CONTINUE 1
#define STATUS_ABORT 0
@@ -279,21 +277,19 @@ static int handle_string (void *ctx, /* {{{ */
const unsigned char *string, size_t string_length)
{
yajl_value_t *v;
- yajl_value_string_t *s;
v = value_alloc (YAJL_TYPE_STRING);
if (v == NULL)
RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory");
- s = YAJL_TO_STRING2 (v);
- s->value = malloc (string_length + 1);
- if (s->value == NULL)
+ v->data.string = malloc (string_length + 1);
+ if (v->data.string == NULL)
{
free (v);
RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory");
}
- memcpy (s->value, string, string_length);
- s->value[string_length] = 0;
+ memcpy(v->data.string, string, string_length);
+ v->data.string[string_length] = 0;
return ((context_add_value (ctx, v) == 0) ? STATUS_CONTINUE : STATUS_ABORT);
} /* }}} int handle_string */
@@ -481,7 +477,7 @@ yajl_value_t * yajl_tree_get(yajl_value_t * n,
if (n->type != YAJL_TYPE_OBJECT) return NULL;
for (i = 0; i < n->data.object.children_num; i++) {
- if (!strcmp(*path, n->data.object.keys[i]->data.string.value)) {
+ if (!strcmp(*path, n->data.object.keys[i]->data.string)) {
n = n->data.object.values[i];
break;
}
@@ -499,9 +495,7 @@ void yajl_tree_free (yajl_value_t *v) /* {{{ */
if (YAJL_IS_STRING (v))
{
- yajl_value_string_t *s = YAJL_TO_STRING2 (v);
-
- free (s->value);
+ free (v->data.string);
free (v);
return;