Skip to content

1.0.9

Compare
Choose a tag to compare
@ProjectSky ProjectSky released this 29 Nov 14:23
· 5 commits to main since this release

feat: add immutable JSON document support

This commit adds support for immutable JSON documents and ensures proper handling
of both mutable and immutable operations. The changes include:

  1. Parse Function Changes:
  • Modify all parse functions to return immutable documents by default:
    • YYJSONObject.FromString
    • YYJSONObject.FromFile
    • YYJSONArray.FromString
    • YYJSONArray.FromFile
    • YYJSON.Parse
  • Require explicit conversion to mutable using YYJSON.ToMutable when modification is needed
  • Improve parse performance by avoiding unnecessary mutable document creation
  1. New Native Functions:
  • Add YYJSON.IsMutable.get to check if a JSON value is mutable
  • Add YYJSON.IsImmutable.get to check if a JSON value is immutable
  • Add YYJSON.ToMutable to convert an immutable JSON value to mutable
  • Add YYJSON.ToImmutable to convert a mutable JSON value to immutable
  1. Core Changes:
  • Add immutable document support in YYJsonWrapper
  • Add immutable iterators for objects and arrays
  • Add IsMutable() and IsImmutable() checks
  1. Function Updates:
  • Add immutable support for value type checking functions
  • Add immutable support for array operations (get, size, iterate)
  • Add immutable support for object operations (get, iterate)
  • Add immutable support for document comparison and copying
  • Add immutable checks for modification operations
  1. Safety Improvements:
  • Add proper handle checks for operations with multiple JSON values
  • Add clear error messages for immutable modification attempts
  • Ensure proper memory management for both document types
  1. Performance Improvements:
    Parse operations:
  • Before: 891.95 MB/s (1481.02 ops/sec)
  • After: 2502.53 MB/s (4155.23 ops/sec)
  • Improvement: 2.80x faster

Stringify operations:

  • Before: 4229.64 MB/s (7022.96 ops/sec)
  • After: 4768.86 MB/s (7918.31 ops/sec)
  • Improvement: 1.12x faster

This change maintains backward compatibility while adding support for
read-only JSON documents and significantly improves parsing performance.
The new native functions provide full control over JSON document mutability.
Parse functions now return immutable documents by default, requiring explicit
conversion to mutable when modifications are needed, which helps prevent
unnecessary mutable document creation and improves performance.