Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no copy api variants to json interface #1138

Merged
merged 7 commits into from
Jul 30, 2024
Merged

Add no copy api variants to json interface #1138

merged 7 commits into from
Jul 30, 2024

Conversation

DmitriyMusatkin
Copy link
Contributor

Issue #, if available:

Description of changes:
There are several json apis that currently take key by cursor, including some heavily used apis like get_object or has_object. Since underlying lib relies on const char, that means that every one of those apis needs to make a temp copy of the key. In grand scheme of things copies are cheap, but for heavy users of json (ex. endpoint resolution) cost ends up quickly.

This PR adds const char variants for all functions taking a key to avoid a copy. And as a side bonus you can now just write get_object(json, "field_name"), which is cleaner in my opinion than having to wrap it in cursor.

Can we just make cursor version not do a copy? Not without major surgery of cJson, which internally relies on c strings a lot.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

source/json.c Show resolved Hide resolved
include/aws/common/json.h Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.

Project coverage is 83.82%. Comparing base (c9ead75) to head (a86e8a9).

Files Patch % Lines
source/json.c 88.23% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1138      +/-   ##
==========================================
+ Coverage   83.38%   83.82%   +0.44%     
==========================================
  Files          57       57              
  Lines        5994     5991       -3     
==========================================
+ Hits         4998     5022      +24     
+ Misses        996      969      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DmitriyMusatkin DmitriyMusatkin merged commit 0a98aa0 into main Jul 30, 2024
53 checks passed
@DmitriyMusatkin DmitriyMusatkin deleted the json_alloc branch July 30, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants