
This patch adds two macros to declare per-type allocators: - JS_DECLARE_ALLOCATOR(TypeName) - JS_DEFINE_ALLOCATOR(TypeName) When used, they add a type-specific CellAllocator that the Heap will delegate allocation requests to. The result of this is that GC objects of the same type always end up within the same HeapBlock, drastically reducing the ability to perform type confusion attacks. It also improves HeapBlock utilization, since each block now has cells sized exactly to the type used within that block. (Previously we only had a handful of block sizes available, and most GC allocations ended up with a large amount of slack in their tails.) There is a small performance hit from this, but I'm sure we can make up for it elsewhere. Note that the old size-based allocators still exist, and we fall back to them for any type that doesn't have its own CellAllocator.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class Segmenter final : public Object {
|
|
JS_OBJECT(Segmenter, Object);
|
|
JS_DECLARE_ALLOCATOR(Segmenter);
|
|
|
|
public:
|
|
enum class SegmenterGranularity {
|
|
Grapheme,
|
|
Word,
|
|
Sentence,
|
|
};
|
|
|
|
virtual ~Segmenter() override = default;
|
|
|
|
String const& locale() const { return m_locale; }
|
|
void set_locale(String locale) { m_locale = move(locale); }
|
|
|
|
SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; }
|
|
void set_segmenter_granularity(StringView);
|
|
StringView segmenter_granularity_string() const;
|
|
|
|
private:
|
|
explicit Segmenter(Object& prototype);
|
|
|
|
String m_locale; // [[Locale]]
|
|
SegmenterGranularity m_segmenter_granularity { SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
|
|
};
|
|
|
|
ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, Segmenter const&, Utf16View const&, double start_index, double end_index);
|
|
|
|
enum class Direction {
|
|
Before,
|
|
After,
|
|
};
|
|
double find_boundary(Segmenter const&, Utf16View const&, double start_index, Direction);
|
|
|
|
}
|