[tarantool-patches] Re: [PATCH v2 3/8] json: lexer_eof and token_cmp helper functions

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Sep 28 01:33:32 MSK 2019


Thanks for the review!

On 03/09/2019 21:24, Konstantin Osipov wrote:
> * Vladislav Shpilevoy <v.shpilevoy at tarantool.org> [19/09/01 00:33]:
>>  /**
>> - * Compare JSON token keys.
>> + * Compare JSON tokens as nodes of a JSON tree. That is, including
>> + * parent references.
>>   */
> 
> Please explain how it is useful. Why not json_tree_node_cmp then?

What is useful? Being able to compare two JSON nodes? Not sure if I
understand the question. I just need to compare two nodes. In several
places. And I added a function for that.

>>  static int
>> -json_token_cmp(const struct json_token *a, const struct json_token *b)
>> +json_token_cmp_in_tree(const struct json_token *a, const struct json_token *b)
>>  {
>>  	if (a->parent != b->parent)
>>  		return a->parent - b->parent;
>> -	if (a->type != b->type)
>> -		return a->type - b->type;
>> -	int ret = 0;
>> -	if (a->type == JSON_TOKEN_STR) {
>> -		if (a->len != b->len)
>> -			return a->len - b->len;
>> -		ret = memcmp(a->str, b->str, a->len);
>> -	} else if (a->type == JSON_TOKEN_NUM) {
>> -		ret = a->num - b->num;
>> -	} else {
>> -		assert(a->type == JSON_TOKEN_ANY);
>> -	}
>> -	return ret;
>> +	return json_token_cmp(a, b);
> 
> Usually when you split code like that you put json_token_cmp right
> below the wrapper, to facilitate review.
> 

If I will put it here, it won't be inlined in non-json sources, because
it is json library's .c file.




More information about the Tarantool-patches mailing list