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
Make object manage its own memory and cheap to copy
Summary:
As whisker has evolved, things have become more "dynamic":
- `native_function` exists and is commonly used
- property lookups happen mostly via `native_object` or `native_handle<>`.
All of these APIs deal with `object::ptr` (not `object` directly) because they *may* need to be dynamically allocated on the heap.
In future diffs, I plan to move APIs away from `object::ptr` where possible. Because:
* Its use has resulted in the proliferation of `manage_as_static`, `manage_derived`, `manage_derived_ref` everywhere because we need "chains" of `shared_ptr` to avoid copying `whisker::object`. It makes the code hard to read.
* It is pessimistic for the common case (`boolean`, `i64`, `string`, `native_object::ptr` need to be heap-allocated) while "optimizing" for the uncommon case (`array`, `map`).
This diff moves `map` and `array` to use `managed_ptr` to solve the problems above and still avoid deep-copying `map` and `array`. Now, copying `object` is *always* cheap. Since `object` has an immutable API (except move copy/assign), we are fine to share `map` and `array` between instances
Reviewed By: iahs
Differential Revision: D71095233
fbshipit-source-id: 3089b2687f0396b7cef053800c0a454938a7490a
0 commit comments