diff options
author | Linus Groh <mail@linusgroh.de> | 2022-02-09 09:40:49 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-09 12:25:27 +0000 |
commit | a863363b06267a859bdc01e15546fc2aa7884117 (patch) | |
tree | fc228ea83098071393ae4ece539b01ebac174912 /Userland/Libraries/LibJS/Forward.h | |
parent | 3c88749800e624701b93ab3fb82e52def4a7b78b (diff) | |
download | serenity-a863363b06267a859bdc01e15546fc2aa7884117.zip |
LibJS: Let MarkedVector<T> inherit from Vector and handle Cell* + Value
Note: MarkedVector is still relatively new and has zero users right now,
so these changes don't affect any code other than the class itself.
Reasons for this are the rather limited API:
- Despite the name and unlike MarkedValueList, MarkedVector isn't
actually a Vector, it *wraps* a Vector. This means that plenty of
convenient APIs are unavailable and have to be exported on the class
separately and forwarded to the internal Vector, or need to go through
the exposed Span - both not great options.
- Exposing append(Cell*) and prepend(Cell*) on the base class means that
it was possible to append any Cell type, not just T! All the strong
typing guarantees are basically gone, and MarkedVector doesn't do much
more than casting Cells to the appropriate type through the exposed
Span.
All of this combined means that MarkedVector - in its current form -
doesn't provide much value over MarkedValueList, and that we have to
maintain two separate, yet almost identical classes.
Let's fix this!
The updated MarkedVector steals various concepts from the existing
MarkedValueList, especially the ability to copy. On the other hand, it
remains generic enough to handle both Cell* and Value for T, making
MarkedValueList effectively redundant :^)
Additionally, by inheriting from Vector we get all the current and
future APIs without having to select and expose them separately.
MarkedVectorBase remains and takes care of communicating creation and
destruction of the class to the heap. Visiting the contained values is
handled via a pure virtual method gather_roots(), which is being called
by the Heap's function of the same name; much like the VM has one.
From there, values are added to the roots HashTable if they are cells
for T = Value, and unconditionally for any other T.
As a small additional improvement the template now also takes an
inline_capacity parameter, defaulting to 32, and forwards it to the
Vector template; allowing for possible future optimizations of current
uses of MarkedValueList, which hard-codes it to 32.
Diffstat (limited to 'Userland/Libraries/LibJS/Forward.h')
-rw-r--r-- | Userland/Libraries/LibJS/Forward.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index 9a35729af8..560a07db2a 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -6,6 +6,8 @@ #pragma once +#include <AK/Types.h> + #define JS_DECLARE_NATIVE_FUNCTION(name) \ static JS::ThrowCompletionOr<JS::Value> name(JS::VM&, JS::GlobalObject&) @@ -241,7 +243,7 @@ class ThrowCompletionOr; template<class T> class Handle; -template<class T> +template<class T, size_t inline_capacity = 32> class MarkedVector; namespace Bytecode { |