Skip to content

Commit

Permalink
Replace usage of strbuf_append with strbuf_appendint
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jun 21, 2024
1 parent 0493d66 commit 0f02569
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
23 changes: 15 additions & 8 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25145,7 +25145,9 @@ bool flecs_rest_put_entity(
return true;
}

ecs_strbuf_append(&reply->body, "{\"id\":\"%u\"}", (uint32_t)result);
ecs_strbuf_appendlit(&reply->body, "{\"id\":\"");
ecs_strbuf_appendint(&reply->body, (uint32_t)result);
ecs_strbuf_appendlit(&reply->body, "\"}");

return true;
}
Expand Down Expand Up @@ -25973,8 +25975,10 @@ void flecs_rest_reply_table_append_memory(
}

ecs_strbuf_list_push(reply, "{", ",");
ecs_strbuf_list_append(reply, "\"used\":%d", used);
ecs_strbuf_list_append(reply, "\"allocated\":%d", allocated);
ecs_strbuf_list_appendlit(reply, "\"used\":");
ecs_strbuf_appendint(reply, used);
ecs_strbuf_list_appendlit(reply, "\"allocated\":");
ecs_strbuf_appendint(reply, allocated);
ecs_strbuf_list_pop(reply, "}");
}

Expand All @@ -25986,11 +25990,13 @@ void flecs_rest_reply_table_append(
{
ecs_strbuf_list_next(reply);
ecs_strbuf_list_push(reply, "{", ",");
ecs_strbuf_list_append(reply, "\"id\":%u", (uint32_t)table->id);
ecs_strbuf_list_appendstr(reply, "\"type\":");
ecs_strbuf_list_appendlit(reply, "\"id\":");
ecs_strbuf_appendint(reply, (uint32_t)table->id);
ecs_strbuf_list_appendlit(reply, "\"type\":");
flecs_rest_reply_table_append_type(world, reply, table);
ecs_strbuf_list_append(reply, "\"count\":%d", ecs_table_count(table));
ecs_strbuf_list_append(reply, "\"memory\":");
ecs_strbuf_list_appendlit(reply, "\"count\":");
ecs_strbuf_appendint(reply, ecs_table_count(table));
ecs_strbuf_list_appendlit(reply, "\"memory\":");
flecs_rest_reply_table_append_memory(reply, table);
ecs_strbuf_list_pop(reply, "}");
}
Expand Down Expand Up @@ -26242,7 +26248,8 @@ bool flecs_rest_get_commands_capture(
(void)req;
const ecs_world_info_t *wi = ecs_get_world_info(world);
ecs_strbuf_appendstr(&reply->body, "{");
ecs_strbuf_append(&reply->body, "\"frame\":%u", wi->frame_count_total);
ecs_strbuf_appendlit(&reply->body, "\"frame\":");
ecs_strbuf_appendint(&reply->body, wi->frame_count_total);
ecs_strbuf_appendstr(&reply->body, "}");

ecs_map_init_if(&impl->cmd_captures, &world->allocator);
Expand Down
2 changes: 1 addition & 1 deletion flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ void ecs_os_set_api_defaults(void);
#if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW)
#define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2)
#define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
#define ecs_os_vsnprintf(ptr, len, fmt, args) vsprintf_s(ptr, ECS_CAST(size_t, len), fmt, args)
#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
#define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2)
#define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len))
#else
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/os_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void ecs_os_set_api_defaults(void);
#if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW)
#define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2)
#define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
#define ecs_os_vsnprintf(ptr, len, fmt, args) vsprintf_s(ptr, ECS_CAST(size_t, len), fmt, args)
#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
#define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2)
#define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len))
#else
Expand Down
23 changes: 15 additions & 8 deletions src/addons/rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ bool flecs_rest_put_entity(
return true;
}

ecs_strbuf_append(&reply->body, "{\"id\":\"%u\"}", (uint32_t)result);
ecs_strbuf_appendlit(&reply->body, "{\"id\":\"");
ecs_strbuf_appendint(&reply->body, (uint32_t)result);
ecs_strbuf_appendlit(&reply->body, "\"}");

return true;
}
Expand Down Expand Up @@ -1079,8 +1081,10 @@ void flecs_rest_reply_table_append_memory(
}

ecs_strbuf_list_push(reply, "{", ",");
ecs_strbuf_list_append(reply, "\"used\":%d", used);
ecs_strbuf_list_append(reply, "\"allocated\":%d", allocated);
ecs_strbuf_list_appendlit(reply, "\"used\":");
ecs_strbuf_appendint(reply, used);
ecs_strbuf_list_appendlit(reply, "\"allocated\":");
ecs_strbuf_appendint(reply, allocated);
ecs_strbuf_list_pop(reply, "}");
}

Expand All @@ -1092,11 +1096,13 @@ void flecs_rest_reply_table_append(
{
ecs_strbuf_list_next(reply);
ecs_strbuf_list_push(reply, "{", ",");
ecs_strbuf_list_append(reply, "\"id\":%u", (uint32_t)table->id);
ecs_strbuf_list_appendstr(reply, "\"type\":");
ecs_strbuf_list_appendlit(reply, "\"id\":");
ecs_strbuf_appendint(reply, (uint32_t)table->id);
ecs_strbuf_list_appendlit(reply, "\"type\":");
flecs_rest_reply_table_append_type(world, reply, table);
ecs_strbuf_list_append(reply, "\"count\":%d", ecs_table_count(table));
ecs_strbuf_list_append(reply, "\"memory\":");
ecs_strbuf_list_appendlit(reply, "\"count\":");
ecs_strbuf_appendint(reply, ecs_table_count(table));
ecs_strbuf_list_appendlit(reply, "\"memory\":");
flecs_rest_reply_table_append_memory(reply, table);
ecs_strbuf_list_pop(reply, "}");
}
Expand Down Expand Up @@ -1348,7 +1354,8 @@ bool flecs_rest_get_commands_capture(
(void)req;
const ecs_world_info_t *wi = ecs_get_world_info(world);
ecs_strbuf_appendstr(&reply->body, "{");
ecs_strbuf_append(&reply->body, "\"frame\":%u", wi->frame_count_total);
ecs_strbuf_appendlit(&reply->body, "\"frame\":");
ecs_strbuf_appendint(&reply->body, wi->frame_count_total);
ecs_strbuf_appendstr(&reply->body, "}");

ecs_map_init_if(&impl->cmd_captures, &world->allocator);
Expand Down

0 comments on commit 0f02569

Please sign in to comment.