Skip to content

Make the Short JsonValue optional (and ideally just make JsonValue::String use a string pool for small sizes?) #10

@navi-desu

Description

@navi-desu

i was using the json crate to write a json-ld processor, and hit the problem of it spilling JsonValue::Sort(_) on, well, short strings.

not only is this a pain, because now everywhere that i would handle strings i now need to handle sorts as well (and uses of if let JsonValue::String(str) = json.get(key) now would need to have all the code duplicated to handle else if let JsonValue::Short = json.get(key) as well (or one would need to normalize both to a variable but at that point if it's a short you're allocating to be able to handle it in a streamlined way)

and since Short is a stack array, of 30 chars, it could be a problem if too many where made, as the lib doesn't track stack size, could lead to a stack overflow.

ideally, instead of a different type, JsonValue::String could just get it's memory from a string pool instead, if it's a short string. this would simplify handling of the data, and avoid the possible stack overflow problem.

proposed solution: initially just add a feature flag that disables parsing into shorts all together (temporarily), then adapt JsonValue::String to use a string pool on short string and a normal allocated String on long string


initially i would open this issue on the json-rs github, but it seems dead, while this fork seems alive

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions