mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
d5fdc6096c
`CharacterBitmap` instances are generated at run-time and put on the heap, but they can be created in a `constexpr` context and stored in static memory. Also, remove additional `width` and `height` `static` values in favor of using the `constexpr` member functions of `CharacterBitmap`. These changes also include the removal of some initialization code which tests if the `CharacterBitmap` is created since it is always created and removes function-local `static` values which cause run-time branches to ensure it is initialized each time the function is called.
40 lines
969 B
C++
40 lines
969 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Size.h"
|
|
#include <AK/RefCounted.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/StringView.h>
|
|
|
|
namespace Gfx {
|
|
|
|
class CharacterBitmap {
|
|
public:
|
|
CharacterBitmap() = delete;
|
|
constexpr CharacterBitmap(StringView ascii_data, unsigned width, unsigned height)
|
|
: m_bits(ascii_data)
|
|
, m_size(width, height)
|
|
{
|
|
}
|
|
|
|
constexpr ~CharacterBitmap() = default;
|
|
|
|
constexpr bool bit_at(unsigned x, unsigned y) const { return m_bits[y * width() + x] == '#'; }
|
|
constexpr StringView bits() const { return m_bits; }
|
|
|
|
constexpr IntSize size() const { return m_size; }
|
|
constexpr unsigned width() const { return m_size.width(); }
|
|
constexpr unsigned height() const { return m_size.height(); }
|
|
|
|
private:
|
|
StringView m_bits {};
|
|
IntSize m_size {};
|
|
};
|
|
|
|
}
|