mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
Bitmap: De-duplicate bitmasks
Problem: - Bitmasks are duplicated. - Bitmasks are C-style arrays. Solution: - Move bitmasks to BitmapView.h. - Change C-style arrays to be AK::Array for added safety.
This commit is contained in:
parent
9c19e62675
commit
d25d4ec0ee
Notes:
sideshowbarker
2024-07-18 17:44:09 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/d25d4ec0eee Pull-request: https://github.com/SerenityOS/serenity/pull/7265
2 changed files with 4 additions and 6 deletions
|
@ -119,9 +119,6 @@ public:
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static const u8 bitmask_first_byte[8] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 };
|
|
||||||
static const u8 bitmask_last_byte[8] = { 0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F };
|
|
||||||
|
|
||||||
u8* first = &m_data[start / 8];
|
u8* first = &m_data[start / 8];
|
||||||
u8* last = &m_data[(start + len) / 8];
|
u8* last = &m_data[(start + len) / 8];
|
||||||
u8 byte_mask = bitmask_first_byte[start % 8];
|
u8 byte_mask = bitmask_first_byte[start % 8];
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Array.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
@ -13,6 +14,9 @@
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
static constexpr Array bitmask_first_byte = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 };
|
||||||
|
static constexpr Array bitmask_last_byte = { 0x00, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F };
|
||||||
|
|
||||||
class BitmapView {
|
class BitmapView {
|
||||||
public:
|
public:
|
||||||
BitmapView(u8* data, size_t size)
|
BitmapView(u8* data, size_t size)
|
||||||
|
@ -49,9 +53,6 @@ public:
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
static const u8 bitmask_first_byte[8] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 };
|
|
||||||
static const u8 bitmask_last_byte[8] = { 0x00, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F };
|
|
||||||
|
|
||||||
size_t count;
|
size_t count;
|
||||||
const u8* first = &m_data[start / 8];
|
const u8* first = &m_data[start / 8];
|
||||||
const u8* last = &m_data[(start + len) / 8];
|
const u8* last = &m_data[(start + len) / 8];
|
||||||
|
|
Loading…
Reference in a new issue