mirror of
https://github.com/json-c/json-c.git
synced 2026-03-13 18:19:06 +08:00
Kick json_type_string out of struct json_object.
The default is now that string data is stored inline at the end of json_object, though to allow for json_object_set_string() to set a _longer_ string, we still need to allow for the possibility of a separate char * pointer. All json types have been split out now, next step it cleanup.
This commit is contained in:
@@ -46,7 +46,7 @@ struct json_object_base // XAX rename to json_object after conversion
|
||||
struct printbuf *_pb;
|
||||
json_object_delete_fn *_user_delete;
|
||||
void *_userdata;
|
||||
char data[1]; // Actually a struct json_object_${o_type}
|
||||
char data[1]; // Actually the rest of a struct json_object_${o_type}
|
||||
};
|
||||
|
||||
struct json_object_object
|
||||
@@ -83,8 +83,14 @@ struct json_object_int
|
||||
struct json_object_string
|
||||
{
|
||||
struct json_object_base base;
|
||||
size_t len;
|
||||
char data[1]; // Actually longer
|
||||
ssize_t len; // Signed b/c negative lengths indicate data is a pointer
|
||||
// Consider adding an "alloc" field here, if json_object_set_string calls
|
||||
// to expand the length of a string are common operations to perform.
|
||||
union
|
||||
{
|
||||
char idata[1]; // Immediate data. Actually longer
|
||||
char *pdata; // Only when len < 0
|
||||
} c_string;
|
||||
};
|
||||
|
||||
struct json_object
|
||||
@@ -95,21 +101,9 @@ struct json_object
|
||||
json_object_private_delete_fn *_delete;
|
||||
json_object_to_json_string_fn *_to_json_string;
|
||||
struct printbuf *_pb;
|
||||
union data
|
||||
{
|
||||
struct
|
||||
{
|
||||
union
|
||||
{
|
||||
/* optimize: if we have small strings, we can store them
|
||||
* directly. This saves considerable CPU cycles AND memory.
|
||||
*/
|
||||
char *ptr;
|
||||
char data[LEN_DIRECT_STRING_DATA];
|
||||
} str;
|
||||
int len;
|
||||
} c_string;
|
||||
} o;
|
||||
int dummyval; // XAX temp spacer to catch casting errors
|
||||
int du1mmyval; // XAX spacer
|
||||
int d2ummyval; // XAX spacer
|
||||
json_object_delete_fn *_user_delete;
|
||||
void *_userdata;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user