Skip to content

Commit 4a4374f

Browse files
committed
WIP: object-json speedups
1 parent 014f928 commit 4a4374f

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

lib/filterx/object-json.c

+27-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "scanner/list-scanner/list-scanner.h"
3636
#include "str-repr/encode.h"
3737

38-
static gboolean
38+
#define json_object_get_type(jso) (*((int *) jso))
39+
40+
static inline gboolean
3941
_is_json_cacheable(struct json_object *jso)
4042
{
4143
if (json_object_get_type(jso) == json_type_double && JSON_C_MAJOR_VERSION == 0 && JSON_C_MINOR_VERSION < 14)
@@ -53,6 +55,30 @@ _is_json_cacheable(struct json_object *jso)
5355
return TRUE;
5456
}
5557

58+
static inline FilterXObject *
59+
filterx_json_get_cached_object(struct json_object *jso)
60+
{
61+
if (!_is_json_cacheable(jso))
62+
return NULL;
63+
64+
if (json_object_get_type(jso) == json_type_double)
65+
{
66+
/*
67+
* This is a workaround to ditch builtin serializer for double objects
68+
* that are set when parsing from a string representation.
69+
* json_object_double_new_ds() will set userdata to the string
70+
* representation of the number, as extracted from the JSON source.
71+
*
72+
* Changing the value of the double to the same value, ditches this,
73+
* but only if necessary.
74+
*/
75+
json_object_set_double(jso, json_object_get_double(jso));
76+
}
77+
78+
return (FilterXObject *) json_object_get_userdata(jso);
79+
}
80+
81+
5682
static int
5783
_deep_copy_filterx_object_ref(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst)
5884
{
@@ -154,28 +180,6 @@ filterx_json_associate_cached_object(struct json_object *jso, FilterXObject *fil
154180
json_object_set_userdata(jso, filterx_obj, NULL);
155181
}
156182

157-
FilterXObject *
158-
filterx_json_get_cached_object(struct json_object *jso)
159-
{
160-
if (!_is_json_cacheable(jso))
161-
return NULL;
162-
163-
if (json_object_get_type(jso) == json_type_double)
164-
{
165-
/*
166-
* This is a workaround to ditch builtin serializer for double objects
167-
* that are set when parsing from a string representation.
168-
* json_object_double_new_ds() will set userdata to the string
169-
* representation of the number, as extracted from the JSON source.
170-
*
171-
* Changing the value of the double to the same value, ditches this,
172-
* but only if necessary.
173-
*/
174-
json_object_set_double(jso, json_object_get_double(jso));
175-
}
176-
177-
return (FilterXObject *) json_object_get_userdata(jso);
178-
}
179183

180184
FilterXObject *
181185
filterx_json_new_from_repr(const gchar *repr, gssize repr_len)

lib/filterx/object-json.h

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const gchar *filterx_json_array_to_json_literal(FilterXObject *s);
5353
FilterXObject *filterx_json_convert_json_to_object(FilterXObject *root_obj, FilterXWeakRef *root_container,
5454
struct json_object *jso);
5555
void filterx_json_associate_cached_object(struct json_object *jso, FilterXObject *filterx_object);
56-
FilterXObject *filterx_json_get_cached_object(struct json_object *jso);
5756

5857
struct json_object *filterx_json_object_get_value(FilterXObject *s);
5958
struct json_object *filterx_json_array_get_value(FilterXObject *s);

0 commit comments

Comments
 (0)