mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
AK+LibWeb: Use segmented vector to store commands in RecordingPainter
Using a vector to represent a list of painting commands results in many reallocations, especially on pages with a lot of content. This change addresses it by introducing a SegmentedVector, which allows fast appending by representing a list as a sequence of fixed-size vectors. Currently, this new data structure supports only the operations used in RecordingPainter, which are appending and iterating.
This commit is contained in:
parent
97f676dbf2
commit
e394971209
4 changed files with 99 additions and 1 deletions
28
Tests/AK/TestSegmentedVector.cpp
Normal file
28
Tests/AK/TestSegmentedVector.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/SegmentedVector.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
TEST_CASE(append)
|
||||
{
|
||||
AK::SegmentedVector<int, 2> segmented_vector;
|
||||
segmented_vector.append(1);
|
||||
segmented_vector.append(2);
|
||||
segmented_vector.append(3);
|
||||
EXPECT_EQ(segmented_vector.size(), 3u);
|
||||
}
|
||||
|
||||
TEST_CASE(at)
|
||||
{
|
||||
AK::SegmentedVector<int, 2> segmented_vector;
|
||||
segmented_vector.append(1);
|
||||
segmented_vector.append(2);
|
||||
segmented_vector.append(3);
|
||||
EXPECT_EQ(segmented_vector[0], 1);
|
||||
EXPECT_EQ(segmented_vector[1], 2);
|
||||
EXPECT_EQ(segmented_vector[2], 3);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue