1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 08:17:35 +00:00

ByteBuffer: Remove pointer() in favor of data()

We had two ways to get the data inside a ByteBuffer. That was silly.
This commit is contained in:
Andreas Kling 2019-09-30 08:57:01 +02:00
parent dd696e7c75
commit 8f45a259fc
30 changed files with 89 additions and 92 deletions

View file

@ -44,7 +44,7 @@ void CConfigFile::reparse()
while (file->can_read_line()) {
auto line = file->read_line(BUFSIZ);
auto* cp = (const char*)line.pointer();
auto* cp = (const char*)line.data();
while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
++cp;

View file

@ -38,7 +38,7 @@ void CHttpJob::on_socket_connected()
}
auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) {
fprintf(stderr, "CHttpJob: Expected 3-part HTTP status, got '%s'\n", line.pointer());
fprintf(stderr, "CHttpJob: Expected 3-part HTTP status, got '%s'\n", line.data());
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
bool ok;

View file

@ -38,7 +38,7 @@ ByteBuffer CIODevice::read(int max_size)
if (!max_size)
return {};
auto buffer = ByteBuffer::create_uninitialized(max_size);
auto* buffer_ptr = (char*)buffer.pointer();
auto* buffer_ptr = (char*)buffer.data();
int remaining_buffer_space = buffer.size();
int taken_from_buffered = 0;
if (!m_buffered_data.is_empty()) {

View file

@ -119,7 +119,7 @@ ByteBuffer CSocket::receive(int max_size)
bool CSocket::send(const ByteBuffer& data)
{
int nsent = ::send(fd(), data.pointer(), data.size(), 0);
int nsent = ::send(fd(), data.data(), data.size(), 0);
if (nsent < 0) {
set_error(errno);
return false;

View file

@ -134,7 +134,7 @@ RefPtr<Font> Font::load_from_file(const StringView& path)
if (!mapped_file.is_valid())
return nullptr;
auto font = load_from_memory((const u8*)mapped_file.pointer());
auto font = load_from_memory((const u8*)mapped_file.data());
font->m_mapped_file = move(mapped_file);
return font;
}
@ -166,7 +166,7 @@ bool Font::write_to_file(const StringView& path)
stream << ByteBuffer::wrap(m_glyph_widths, 256);
ASSERT(stream.at_end());
ssize_t nwritten = write(fd, buffer.pointer(), buffer.size());
ssize_t nwritten = write(fd, buffer.data(), buffer.size());
ASSERT(nwritten == (ssize_t)buffer.size());
int rc = close(fd);
ASSERT(rc == 0);

View file

@ -54,7 +54,7 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, size_t pitch, RG
GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, MappedFile&& mapped_file)
: m_size(size)
, m_data((RGBA32*)mapped_file.pointer())
, m_data((RGBA32*)mapped_file.data())
, m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16))
, m_format(format)
, m_mapped_file(move(mapped_file))

View file

@ -138,7 +138,7 @@ RefPtr<GraphicsBitmap> load_png(const StringView& path)
MappedFile mapped_file(path);
if (!mapped_file.is_valid())
return nullptr;
auto bitmap = load_png_impl((const u8*)mapped_file.pointer(), mapped_file.size());
auto bitmap = load_png_impl((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
bitmap->set_mmap_name(String::format("GraphicsBitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), canonicalized_path(path).characters()));
return bitmap;
@ -271,7 +271,7 @@ template<bool has_alpha, u8 filter_type>
case 2:
if (context.bit_depth == 8) {
for (int y = 0; y < context.height; ++y) {
auto* triplets = (Triplet*)context.scanlines[y].data.pointer();
auto* triplets = (Triplet*)context.scanlines[y].data.data();
for (int i = 0; i < context.width; ++i) {
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
pixel.r = triplets[i].r;
@ -282,7 +282,7 @@ template<bool has_alpha, u8 filter_type>
}
} else if (context.bit_depth == 16) {
for (int y = 0; y < context.height; ++y) {
auto* triplets = (Triplet16*)context.scanlines[y].data.pointer();
auto* triplets = (Triplet16*)context.scanlines[y].data.data();
for (int i = 0; i < context.width; ++i) {
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
pixel.r = triplets[i].r & 0xFF;
@ -298,11 +298,11 @@ template<bool has_alpha, u8 filter_type>
case 6:
if (context.bit_depth == 8) {
for (int y = 0; y < context.height; ++y) {
memcpy(context.bitmap->scanline(y), context.scanlines[y].data.pointer(), context.scanlines[y].data.size());
memcpy(context.bitmap->scanline(y), context.scanlines[y].data.data(), context.scanlines[y].data.size());
}
} else if (context.bit_depth == 16) {
for (int y = 0; y < context.height; ++y) {
auto* triplets = (Quad16*)context.scanlines[y].data.pointer();
auto* triplets = (Quad16*)context.scanlines[y].data.data();
for (int i = 0; i < context.width; ++i) {
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
pixel.r = triplets[i].r & 0xFF;
@ -317,7 +317,7 @@ template<bool has_alpha, u8 filter_type>
break;
case 3:
for (int y = 0; y < context.height; ++y) {
auto* palette_index = (u8*)context.scanlines[y].data.pointer();
auto* palette_index = (u8*)context.scanlines[y].data.data();
for (int i = 0; i < context.width; ++i) {
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
auto& color = context.palette_data.at((int)palette_index[i]);
@ -346,37 +346,37 @@ template<bool has_alpha, u8 filter_type>
auto filter = context.scanlines[y].filter;
if (filter == 0) {
if (context.has_alpha())
unfilter_impl<true, 0>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<true, 0>(*context.bitmap, y, dummy_scanline.data());
else
unfilter_impl<false, 0>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<false, 0>(*context.bitmap, y, dummy_scanline.data());
continue;
}
if (filter == 1) {
if (context.has_alpha())
unfilter_impl<true, 1>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<true, 1>(*context.bitmap, y, dummy_scanline.data());
else
unfilter_impl<false, 1>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<false, 1>(*context.bitmap, y, dummy_scanline.data());
continue;
}
if (filter == 2) {
if (context.has_alpha())
unfilter_impl<true, 2>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<true, 2>(*context.bitmap, y, dummy_scanline.data());
else
unfilter_impl<false, 2>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<false, 2>(*context.bitmap, y, dummy_scanline.data());
continue;
}
if (filter == 3) {
if (context.has_alpha())
unfilter_impl<true, 3>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<true, 3>(*context.bitmap, y, dummy_scanline.data());
else
unfilter_impl<false, 3>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<false, 3>(*context.bitmap, y, dummy_scanline.data());
continue;
}
if (filter == 4) {
if (context.has_alpha())
unfilter_impl<true, 4>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<true, 4>(*context.bitmap, y, dummy_scanline.data());
else
unfilter_impl<false, 4>(*context.bitmap, y, dummy_scanline.pointer());
unfilter_impl<false, 4>(*context.bitmap, y, dummy_scanline.data());
continue;
}
}
@ -465,7 +465,7 @@ static bool process_IHDR(const ByteBuffer& data, PNGLoadingContext& context)
{
if (data.size() < (int)sizeof(PNG_IHDR))
return false;
auto& ihdr = *(const PNG_IHDR*)data.pointer();
auto& ihdr = *(const PNG_IHDR*)data.data();
context.width = ihdr.width;
context.height = ihdr.height;
context.bit_depth = ihdr.bit_depth;
@ -519,13 +519,13 @@ static bool process_IHDR(const ByteBuffer& data, PNGLoadingContext& context)
static bool process_IDAT(const ByteBuffer& data, PNGLoadingContext& context)
{
context.compressed_data.append(data.pointer(), data.size());
context.compressed_data.append(data.data(), data.size());
return true;
}
static bool process_PLTE(const ByteBuffer& data, PNGLoadingContext& context)
{
context.palette_data.append((const PaletteEntry*)data.pointer(), data.size() / 3);
context.palette_data.append((const PaletteEntry*)data.data(), data.size() / 3);
return true;
}
@ -533,7 +533,7 @@ static bool process_tRNS(const ByteBuffer& data, PNGLoadingContext& context)
{
switch (context.color_type) {
case 3:
context.palette_transparency_data.append(data.pointer(), data.size());
context.palette_transparency_data.append(data.data(), data.size());
break;
}
return true;

View file

@ -108,7 +108,7 @@ int Database::init()
if (!m_file.is_valid())
return -1;
m_view = StringView((const char*)m_file.pointer(), m_file.size());
m_view = StringView((const char*)m_file.data(), m_file.size());
ParseMode mode = ParseMode::UnknownMode;