You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor array handling for value_variant, introduce array_value_base, and improve memory management**
This commit introduces significant refactoring to the handling of array types in the jsonlogic C++ implementation, with the following key changes:
- **Introduced `array_value_base`:**
- Added an abstract base class `array_value_base` to unify array handling and allow for future extensions such as array views.
- All array-related logic in `value_variant` and associated functions now use `array_value_base const*` instead of `array_value const*`.
- **Refactored `array_value`:**
- Now derives from `array_value_base`.
- Internally stores elements in a `std::shared_ptr` for safer memory management and copy semantics.
- Implements `value()` and `copy()` methods for interface consistency.
- **Updated `value_variant` and memory management:**
- All code paths that previously used `array_value const*` now use `array_value_base const*`.
- Copy/move constructors and assignment operators for `value_variant` now correctly handle deep copying and deletion of array objects.
- Helper functions `delete_array`, `copy_array`, and `invalidate_array` manage resource ownership and avoid memory leaks.
- **Visitor pattern and operator handling:**
- Visitors now support both `array_value_base` and `array_value`.
- Logic for array operations (e.g., merge, map, filter, membership, etc.) updated to use new array types and methods.
- Improved type coercion and equality/relational operations for arrays.
- **Logging and evaluation:**
- Replaced direct use of `std::ostream` for logging with a `variant_logger` function type for more flexible logging.
- Updated evaluator and sequence functions to use the new logger type.
- **Test infrastructure:**
- Updated test runner (`testeval.cpp`) to convert results to string representations for comparison.
- Added a new test for the `merge` operator.
- Improved safety and clarity of string table management.
- Marked some classes as non-copyable for safety.
- Added comments and clarified TODOs for future enhancements (e.g., array views).
- Improved assertion and error handling in several places.
This refactor lays the groundwork for future enhancements (such as array views), improves memory safety and clarity of ownership, and unifies array handling across the codebase. The changes also make it easier to extend array support and maintain high performance.
---
**Note:** This commit introduces breaking changes to the API for array handling. All user code and tests have been updated accordingly.
0 commit comments