From 54ee4406f7c5ec73f418b5fc706057017dc68c91 Mon Sep 17 00:00:00 2001 From: FFMG Date: Sat, 16 May 2026 08:36:54 +0200 Subject: [PATCH 1/3] Small performance improvements in get_numbers() and get_floats() --- src/TinyJSON.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/TinyJSON.cpp b/src/TinyJSON.cpp index 758c58d..816b685 100644 --- a/src/TinyJSON.cpp +++ b/src/TinyJSON.cpp @@ -6210,10 +6210,17 @@ namespace TinyJSON std::vector TJValueArray::get_floats() const { + const unsigned int count = get_number_of_items(); std::vector values = {}; - for (unsigned int i = 0; i < get_number_of_items(); ++i) + values.reserve(count); + const unsigned int elements_count = get_number_of_elements(); + for (unsigned int i = 0; i < elements_count; ++i) { - auto value = at(i); + auto* value = element_at(i); + if (value->is_comment()) + { + continue; + } if (!value->is_number()) { ParseResult _parse_result(_parse_options); @@ -6228,10 +6235,17 @@ namespace TinyJSON std::vector TJValueArray::get_numbers() const { + const unsigned int count = get_number_of_items(); std::vector values = {}; - for (unsigned int i = 0; i < get_number_of_items(); ++i) + values.reserve(count); + const unsigned int elements_count = get_number_of_elements(); + for (unsigned int i = 0; i < elements_count; ++i) { - auto value = at(i); + auto* value = element_at(i); + if (value->is_comment()) + { + continue; + } if (!value->is_number()) { ParseResult _parse_result(_parse_options); From 2b90ded84050b59bf3a2b18ab14d0761ee23e7a1 Mon Sep 17 00:00:00 2001 From: FFMG Date: Sat, 16 May 2026 08:37:21 +0200 Subject: [PATCH 2/3] Added tests that did not properly cover get_numbers()/get_floats() with comments. --- tests/testjson5arrays.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/testjson5arrays.cpp b/tests/testjson5arrays.cpp index 4077675..f473497 100644 --- a/tests/testjson5arrays.cpp +++ b/tests/testjson5arrays.cpp @@ -106,3 +106,39 @@ TEST(TJJSON5Arrays, RemoveAllItemsKeepComment) delete tj; } + +TEST(TJJSON5Arrays, GetNumbersWithComments) +{ + const TJCHAR* json = TJCHARPREFIX("[\n 1, \n // comment\n 2\n]"); + parse_options options; + options.specification = parse_options::json5_1_0_0; + auto* tj = TJ::parse(json, options); + ASSERT_NE(nullptr, tj); + auto* jarr = dynamic_cast(tj); + ASSERT_NE(nullptr, jarr); + + std::vector numbers = jarr->get_numbers(); + ASSERT_EQ(2u, numbers.size()); + EXPECT_EQ(1, numbers[0]); + EXPECT_EQ(2, numbers[1]); + + delete tj; +} + +TEST(TJJSON5Arrays, GetFloatsWithComments) +{ + const TJCHAR* json = TJCHARPREFIX("[\n 1.1, \n // comment\n 2.2\n]"); + parse_options options; + options.specification = parse_options::json5_1_0_0; + auto* tj = TJ::parse(json, options); + ASSERT_NE(nullptr, tj); + auto* jarr = dynamic_cast(tj); + ASSERT_NE(nullptr, jarr); + + std::vector floats = jarr->get_floats(); + ASSERT_EQ(2u, floats.size()); + EXPECT_DOUBLE_EQ(1.1, (double)floats[0]); + EXPECT_DOUBLE_EQ(2.2, (double)floats[1]); + + delete tj; +} From 439cb6c02ae10e16dd53cbbfaa52d5793e49435b Mon Sep 17 00:00:00 2001 From: FFMG Date: Sat, 16 May 2026 08:49:58 +0200 Subject: [PATCH 3/3] Added rekease:true apparently needed for the windows runner. --- .github/workflows/c-cpp.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 56d3f44..7370a35 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -39,6 +39,7 @@ jobs: msystem: MINGW64 install: mingw-w64-x86_64-gcc update: true + release: true - name: build and test shell: msys2 {0}