src/json.c

changeset 1055
221e2e2f2c06
parent 1054
fb1076ead56f
child 1057
4e8436c3e806
equal deleted inserted replaced
1054:fb1076ead56f 1055:221e2e2f2c06
803 val, count 803 val, count
804 ); 804 );
805 } 805 }
806 806
807 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child) { 807 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child) {
808 // TODO: optimize - issue #462
809 for (size_t i = 0; i < obj->value.object.values_size; i++) {
810 if (0 == cx_strcmp(name, cx_strcast(obj->value.object.values[i].name))) {
811 // free the original value
812 cxJsonValueFree(obj->value.object.values[i].value);
813 obj->value.object.values[i].value = child;
814 return 0;
815 }
816 }
817
808 CxArrayReallocator value_realloc = cx_array_reallocator(obj->allocator, NULL); 818 CxArrayReallocator value_realloc = cx_array_reallocator(obj->allocator, NULL);
809 assert(obj->type == CX_JSON_OBJECT); 819 assert(obj->type == CX_JSON_OBJECT);
810 cxmutstr k = cx_strdup_a(obj->allocator, name); 820 cxmutstr k = cx_strdup_a(obj->allocator, name);
811 if (k.ptr == NULL) return -1; 821 if (k.ptr == NULL) return -1;
812 CxJsonObjValue kv = {k, child}; 822 CxJsonObjValue kv = {k, child};

mercurial