json icon indicating copy to clipboard operation
json copied to clipboard

Make escape/unescape functions linear and not memory-storming.

Open puffetto opened this issue 5 months ago β€’ 22 comments

Hello,

I am working on a project which does heavy use of JSON pointers (see #4859 ); while digging into the code I saw that the escape/unescape of JSON pointers was not linear, in example escaping "~~~~~~~~~~" requires 10 reallocations and 200 byte copies, escaping ; "~~~~~~~~~~~~~~~~~~~~" requires 20 reallocations and 800 byte copies.

I rewrote these two functions: one allocation and exactly two cycles on the key for escaping, no allocations and at most two loops for unescaping; I understand they are way less readable in this flavour but also way more efficient,

Existing tests already cover all the new code, I had to add iterators to the unit-alt-string "alt_string" class.

I tried to follow the CONTRIBUTING.md document throughly, but it's my first PR to this project, so forgive any mistake.

A.

puffetto avatar Jul 28 '25 10:07 puffetto

Coverage Status

coverage: 99.178% (-0.01%) from 99.191% when pulling f81406f9d9c8200fa229feb2f4915c989192cf8a on puffetto:develop into 3ed64e502a6371311af3c2f309e6525b2f5f6f18 on nlohmann:develop.

coveralls avatar Jul 28 '25 11:07 coveralls

Clang-Tidy fails due to an update. I have not found the time to look into it - probably just some exclusions needed.

nlohmann avatar Jul 28 '25 11:07 nlohmann

Clang-Tidy fails due to an update. I have not found the time to look into it - probably just some exclusions needed.

Oh, I see there are indeed some warnings related to the changed code. Please take a look to fix these.

nlohmann avatar Jul 28 '25 12:07 nlohmann

Clang-Tidy fails due to an update. I have not found the time to look into it - probably just some exclusions needed.

Oh, I see there are indeed some warnings related to the changed code. Please take a look to fix these.

0d06a06629aa72788f7bcf96b2b2dbc4b41cbdd3 Should fix it

puffetto avatar Jul 28 '25 12:07 puffetto

0d06a06 Should fix it

Ok, it did not, more warnings around... will take a look in the evening.

puffetto avatar Jul 28 '25 13:07 puffetto

πŸ”΄ CI is red due to unrelated issues, see https://github.com/nlohmann/json/issues/4869.

nlohmann avatar Jul 29 '25 05:07 nlohmann

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Jul 29 '25 08:07 github-actions[bot]

Please rebase to the latest develop branch as I just merged #4871.

nlohmann avatar Jul 31 '25 18:07 nlohmann

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

github-actions[bot] avatar Aug 31 '25 00:08 github-actions[bot]

Hi @puffetto, can you please rebase?

nlohmann avatar Sep 20 '25 14:09 nlohmann

Hi @puffetto, can you please rebase?

Done, sorry for taking so long, having personal problems these weeks/months.

puffetto avatar Oct 03 '25 07:10 puffetto

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 08:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

github-actions[bot] avatar Oct 03 '25 09:10 github-actions[bot]

πŸ”΄ Amalgamation check failed! πŸ”΄

The source code has not been amalgamated. @puffetto Please read and follow the Contribution Guidelines.

Sorry I made some noise, I was working on the wrong branch and commits we unintentionally propagated here; I did reset now.

puffetto avatar Oct 03 '25 09:10 puffetto

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

github-actions[bot] avatar Nov 03 '25 00:11 github-actions[bot]