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
Notes: sideshowbarker 2024-07-19 11:52:49 +09:00
30 changed files with 89 additions and 92 deletions

View file

@ -43,8 +43,8 @@ public:
bool is_empty() const { return !m_size; }
int size() const { return m_size; }
u8* pointer() { return m_data; }
const u8* pointer() const { return m_data; }
u8* data() { return m_data; }
const u8* data() const { return m_data; }
u8* offset_pointer(int offset) { return m_data + offset; }
const u8* offset_pointer(int offset) const { return m_data + offset; }
@ -130,11 +130,8 @@ public:
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
int size() const { return m_impl ? m_impl->size() : 0; }
u8* data() { return pointer(); }
const u8* data() const { return pointer(); }
u8* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
const u8* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }
u8* data() { return m_impl ? m_impl->data() : nullptr; }
const u8* data() const { return m_impl ? m_impl->data() : nullptr; }
u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
@ -146,7 +143,7 @@ public:
{
if (!m_impl)
return {};
return copy(m_impl->pointer(), m_impl->size());
return copy(m_impl->data(), m_impl->size());
}
// NOTE: trim() does not reallocate.
@ -190,7 +187,7 @@ public:
{
int old_size = size();
grow(size() + data_size);
memcpy(pointer() + old_size, data, data_size);
memcpy(this->data() + old_size, data, data_size);
}
private:
@ -249,7 +246,7 @@ inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(int si
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(int size)
{
auto buffer = ::adopt(*new ByteBufferImpl(size));
memset(buffer->pointer(), 0, size);
memset(buffer->data(), 0, size);
return buffer;
}

View file

@ -18,8 +18,8 @@ public:
bool is_valid() const { return m_map != (void*)-1; }
void unmap();
void* pointer() { return m_map; }
const void* pointer() const { return m_map; }
void* data() { return m_map; }
const void* data() const { return m_map; }
size_t size() const { return m_size; }
private:

View file

@ -21,7 +21,7 @@ void StringBuilder::append(const StringView& str)
if (str.is_empty())
return;
will_append(str.length());
memcpy(m_buffer.pointer() + m_length, str.characters_without_null_termination(), str.length());
memcpy(m_buffer.data() + m_length, str.characters_without_null_termination(), str.length());
m_length += str.length();
}
@ -30,14 +30,14 @@ void StringBuilder::append(const char* characters, int length)
if (!length)
return;
will_append(length);
memcpy(m_buffer.pointer() + m_length, characters, length);
memcpy(m_buffer.data() + m_length, characters, length);
m_length += length;
}
void StringBuilder::append(char ch)
{
will_append(1);
m_buffer.pointer()[m_length] = ch;
m_buffer.data()[m_length] = ch;
m_length += 1;
}
@ -67,14 +67,14 @@ ByteBuffer StringBuilder::to_byte_buffer()
String StringBuilder::to_string()
{
auto string = String((const char*)m_buffer.pointer(), m_length);
auto string = String((const char*)m_buffer.data(), m_length);
clear();
return string;
}
StringView StringBuilder::string_view() const
{
return StringView { (const char*)m_buffer.pointer(), m_length };
return StringView { (const char*)m_buffer.data(), m_length };
}
void StringBuilder::clear()

View file

@ -20,7 +20,7 @@ int main(int argc, char** argv)
auto& response = static_cast<const CHttpResponse&>(*job->response());
printf("%s{%p}: on_receive: code=%d\n", job->class_name(), job.ptr(), response.code());
//printf("payload:\n");
//printf("%s", response.payload().pointer());
//printf("%s", response.payload().data());
printf("payload was %d bytes\n", response.payload().size());
};

View file

@ -207,9 +207,9 @@ void PATAChannel::detect_disks()
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512);
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512);
u8* b = bbuf.pointer();
u16* w = (u16*)wbuf.pointer();
const u16* wbufbase = (u16*)wbuf.pointer();
u8* b = bbuf.data();
u16* w = (u16*)wbuf.data();
const u16* wbufbase = (u16*)wbuf.data();
for (u32 i = 0; i < 256; ++i) {
u16 data = IO::in16(m_io_base + ATA_REG_DATA);
@ -228,7 +228,7 @@ void PATAChannel::detect_disks()
kprintf(
"PATAChannel: Name=\"%s\", C/H/Spt=%u/%u/%u\n",
bbuf.pointer() + 54,
bbuf.data() + 54,
cyls,
heads,
spt);

View file

@ -107,7 +107,7 @@ ByteBuffer DiskBackedFS::read_block(unsigned index) const
auto buffer = ByteBuffer::create_uninitialized(block_size());
//kprintf("created block buffer with size %u\n", block_size());
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
auto* buffer_pointer = buffer.pointer();
auto* buffer_pointer = buffer.data();
bool success = device().read(base_offset, block_size(), buffer_pointer);
ASSERT(success);
ASSERT(buffer.size() == block_size());
@ -126,13 +126,13 @@ ByteBuffer DiskBackedFS::read_blocks(unsigned index, unsigned count) const
if (count == 1)
return read_block(index);
auto blocks = ByteBuffer::create_uninitialized(count * block_size());
u8* out = blocks.pointer();
u8* out = blocks.data();
for (unsigned i = 0; i < count; ++i) {
auto block = read_block(index + i);
if (!block)
return nullptr;
memcpy(out, block.pointer(), block.size());
memcpy(out, block.data(), block.size());
out += block_size();
}

View file

@ -49,7 +49,7 @@ ByteBuffer Ext2FS::read_super_block() const
{
LOCKER(m_lock);
auto buffer = ByteBuffer::create_uninitialized(1024);
bool success = device().read_block(2, buffer.pointer());
bool success = device().read_block(2, buffer.data());
ASSERT(success);
success = device().read_block(3, buffer.offset_pointer(512));
ASSERT(success);
@ -79,7 +79,7 @@ const ext2_super_block& Ext2FS::super_block() const
{
if (!m_cached_super_block)
m_cached_super_block = read_super_block();
return *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
return *reinterpret_cast<ext2_super_block*>(m_cached_super_block.data());
}
const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
@ -97,7 +97,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
#endif
m_cached_group_descriptor_table = read_blocks(first_block_of_bgdt, blocks_to_read);
}
return reinterpret_cast<ext2_group_desc*>(m_cached_group_descriptor_table.pointer())[group_index - 1];
return reinterpret_cast<ext2_group_desc*>(m_cached_group_descriptor_table.data())[group_index - 1];
}
bool Ext2FS::initialize()
@ -321,10 +321,10 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
auto dind_block_contents = read_block(e2inode.i_block[EXT2_DIND_BLOCK]);
if (dind_block_new) {
memset(dind_block_contents.pointer(), 0, dind_block_contents.size());
memset(dind_block_contents.data(), 0, dind_block_contents.size());
dind_block_dirty = true;
}
auto* dind_block_as_pointers = (unsigned*)dind_block_contents.pointer();
auto* dind_block_as_pointers = (unsigned*)dind_block_contents.data();
ASSERT(indirect_block_count <= entries_per_block);
for (unsigned i = 0; i < indirect_block_count; ++i) {
@ -341,10 +341,10 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
auto ind_block_contents = read_block(indirect_block_index);
if (ind_block_new) {
memset(ind_block_contents.pointer(), 0, dind_block_contents.size());
memset(ind_block_contents.data(), 0, dind_block_contents.size());
ind_block_dirty = true;
}
auto* ind_block_as_pointers = (unsigned*)ind_block_contents.pointer();
auto* ind_block_as_pointers = (unsigned*)ind_block_contents.data();
unsigned entries_to_write = new_shape.doubly_indirect_blocks - (i * entries_per_block);
if (entries_to_write > entries_per_block)
@ -430,7 +430,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode(const ext2_inode& e2inod
callback(array_block_index);
auto array_block = read_block(array_block_index);
ASSERT(array_block);
auto* array = reinterpret_cast<const __u32*>(array_block.pointer());
auto* array = reinterpret_cast<const __u32*>(array_block.data());
unsigned count = min(blocks_remaining, entries_per_block);
for (unsigned i = 0; i < count; ++i) {
if (!array[i]) {
@ -646,7 +646,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
int offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
int num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
memcpy(out, block.pointer() + offset_into_block, num_bytes_to_copy);
memcpy(out, block.data() + offset_into_block, num_bytes_to_copy);
remaining_count -= num_bytes_to_copy;
nread += num_bytes_to_copy;
out += num_bytes_to_copy;
@ -755,14 +755,14 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
} else
block = buffer_block;
memcpy(block.pointer() + offset_into_block, in, num_bytes_to_copy);
memcpy(block.data() + offset_into_block, in, num_bytes_to_copy);
if (bi == last_logical_block_index_in_file && num_bytes_to_copy < block_size) {
int padding_start = new_size % block_size;
int padding_bytes = block_size - padding_start;
#ifdef EXT2_DEBUG
dbgprintf("Ext2FSInode::write_bytes padding last block of file with zero x %u (new_size=%u, offset_into_block=%u, num_bytes_to_copy=%u)\n", padding_bytes, new_size, offset_into_block, num_bytes_to_copy);
#endif
memset(block.pointer() + padding_start, 0, padding_bytes);
memset(block.data() + padding_start, 0, padding_bytes);
}
#ifdef EXT2_DEBUG
dbgprintf("Ext2FSInode::write_bytes: writing block %u (offset_into_block: %u)\n", m_block_list[bi], offset_into_block);
@ -799,7 +799,7 @@ bool Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
auto buffer = read_entire();
ASSERT(buffer);
auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer.pointer());
auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer.data());
while (entry < buffer.end_pointer()) {
if (entry->inode != 0) {
@ -867,7 +867,7 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
stream.fill_to_end(0);
ssize_t nwritten = write_bytes(0, directory_data.size(), directory_data.pointer(), nullptr);
ssize_t nwritten = write_bytes(0, directory_data.size(), directory_data.data(), nullptr);
return nwritten == directory_data.size();
}
@ -1006,7 +1006,7 @@ Ext2FS::BlockIndex Ext2FS::allocate_block(GroupIndex preferred_group_index)
auto bitmap_block = read_block(bgd.bg_block_bitmap);
int blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count);
auto block_bitmap = Bitmap::wrap(bitmap_block.pointer(), blocks_in_group);
auto block_bitmap = Bitmap::wrap(bitmap_block.data(), blocks_in_group);
BlockIndex first_block_in_group = (group_index - 1) * blocks_per_group() + first_block_index();
int first_unset_bit_index = block_bitmap.find_first_unset();
ASSERT(first_unset_bit_index != -1);
@ -1136,7 +1136,7 @@ bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
auto block = read_block(bgd.bg_inode_bitmap);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), inodes_per_group());
auto bitmap = Bitmap::wrap(block.data(), inodes_per_group());
return bitmap.get(bit_index);
}
@ -1149,7 +1149,7 @@ bool Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
auto block = read_block(bgd.bg_inode_bitmap);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), inodes_per_group());
auto bitmap = Bitmap::wrap(block.data(), inodes_per_group());
bool current_state = bitmap.get(bit_index);
#ifdef EXT2_DEBUG
dbgprintf("Ext2FS: set_inode_allocation_state(%u) %u -> %u\n", inode_index, current_state, new_state);
@ -1165,7 +1165,7 @@ bool Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
ASSERT(success);
// Update superblock
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.data());
#ifdef EXT2_DEBUG
dbgprintf("Ext2FS: superblock free inode count %u -> %u\n", sb.s_free_inodes_count, sb.s_free_inodes_count - 1);
#endif
@ -1212,7 +1212,7 @@ bool Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
#endif
auto block = read_block(bgd.bg_block_bitmap);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), blocks_per_group());
auto bitmap = Bitmap::wrap(block.data(), blocks_per_group());
bool current_state = bitmap.get(bit_index);
#ifdef EXT2_DEBUG
dbgprintf("Ext2FS: block %u state: %u -> %u\n", block_index, current_state, new_state);
@ -1228,7 +1228,7 @@ bool Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
ASSERT(success);
// Update superblock
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.data());
#ifdef EXT2_DEBUG
dbgprintf("Ext2FS: superblock free block count %u -> %u\n", sb.s_free_blocks_count, sb.s_free_blocks_count - 1);
#endif

View file

@ -168,7 +168,7 @@ ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
if (size < temp_buffer.size())
return -1;
memcpy(buffer, temp_buffer.pointer(), temp_buffer.size());
memcpy(buffer, temp_buffer.data(), temp_buffer.size());
return stream.offset();
}

View file

@ -796,7 +796,7 @@ static ssize_t write_sys_string(InodeIdentifier inode_id, const ByteBuffer& data
{
auto* lockable_string = reinterpret_cast<Lockable<String>*>(variable.address);
LOCKER(lockable_string->lock());
lockable_string->resource() = String((const char*)data.pointer(), data.size());
lockable_string->resource() = String((const char*)data.data(), data.size());
}
variable.notify();
return data.size();

View file

@ -714,7 +714,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
// FIXME: We should limit the recursion here and return -ELOOP if it goes to deep.
auto symlink_target = resolve_path(
StringView(symlink_contents.pointer(),
StringView(symlink_contents.data(),
symlink_contents.size()),
current_parent,
parent_custody,

View file

@ -34,7 +34,7 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
{
ksym_lowest_address = 0xffffffff;
ksym_highest_address = 0;
auto* bufptr = (const char*)buffer.pointer();
auto* bufptr = (const char*)buffer.data();
auto* start_of_name = bufptr;
u32 address = 0;

View file

@ -58,7 +58,7 @@ void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet
{
int size_in_bytes = sizeof(EthernetFrameHeader) + sizeof(ARPPacket);
auto buffer = ByteBuffer::create_zeroed(size_in_bytes);
auto* eth = (EthernetFrameHeader*)buffer.pointer();
auto* eth = (EthernetFrameHeader*)buffer.data();
eth->set_source(mac_address());
eth->set_destination(destination);
eth->set_ether_type(EtherType::ARP);
@ -72,7 +72,7 @@ void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Addr
{
size_t size_in_bytes = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet) + payload_size;
auto buffer = ByteBuffer::create_zeroed(size_in_bytes);
auto& eth = *(EthernetFrameHeader*)buffer.pointer();
auto& eth = *(EthernetFrameHeader*)buffer.data();
eth.set_source(mac_address());
eth.set_destination(destination_mac);
eth.set_ether_type(EtherType::IPv4);

View file

@ -264,7 +264,7 @@ void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet)
(u16)request.sequence_number);
size_t icmp_packet_size = ipv4_packet.payload_size();
auto buffer = ByteBuffer::create_zeroed(icmp_packet_size);
auto& response = *(ICMPEchoPacket*)buffer.pointer();
auto& response = *(ICMPEchoPacket*)buffer.data();
response.header.set_type(ICMPType::EchoReply);
response.header.set_code(0);
response.identifier = request.identifier;

View file

@ -140,7 +140,7 @@ int TCPSocket::protocol_send(const void* data, int data_length)
void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size)
{
auto buffer = ByteBuffer::create_zeroed(sizeof(TCPPacket) + payload_size);
auto& tcp_packet = *(TCPPacket*)(buffer.pointer());
auto& tcp_packet = *(TCPPacket*)(buffer.data());
ASSERT(local_port());
tcp_packet.set_source_port(local_port());
tcp_packet.set_destination_port(peer_port());
@ -194,7 +194,7 @@ void TCPSocket::send_outgoing_packets()
packet.tx_counter++;
#ifdef TCP_SOCKET_DEBUG
auto& tcp_packet = *(TCPPacket*)(packet.buffer.pointer());
auto& tcp_packet = *(TCPPacket*)(packet.buffer.data());
kprintf("sending tcp packet from %s:%u to %s:%u with (%s%s%s%s) seq_no=%u, ack_no=%u, tx_counter=%u\n",
local_address().to_string().characters(),
local_port(),

View file

@ -67,7 +67,7 @@ int UDPSocket::protocol_send(const void* data, int data_length)
if (routing_decision.is_zero())
return -EHOSTUNREACH;
auto buffer = ByteBuffer::create_zeroed(sizeof(UDPPacket) + data_length);
auto& udp_packet = *(UDPPacket*)(buffer.pointer());
auto& udp_packet = *(UDPPacket*)(buffer.data());
udp_packet.set_source_port(local_port());
udp_packet.set_destination_port(peer_port());
udp_packet.set_length(sizeof(UDPPacket) + data_length);

View file

@ -1240,7 +1240,7 @@ int Process::sys$readlink(const char* path, char* buffer, ssize_t size)
if (!contents)
return -EIO; // FIXME: Get a more detailed error from VFS.
memcpy(buffer, contents.pointer(), min(size, (ssize_t)contents.size()));
memcpy(buffer, contents.data(), min(size, (ssize_t)contents.size()));
if (contents.size() + 1 < size)
buffer[contents.size()] = '\0';
return 0;

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;

View file

@ -42,7 +42,7 @@ static void load_etc_hosts()
auto line = file->read_line(1024);
if (line.is_empty())
break;
auto str_line = String((const char*)line.pointer(), line.size() - 1, Chomp);
auto str_line = String((const char*)line.data(), line.size() - 1, Chomp);
auto fields = str_line.split('\t');
auto sections = fields[0].split('.');
@ -254,7 +254,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
dst_addr.sin_port = htons(53);
rc = inet_pton(AF_INET, DNS_IP.characters(), &dst_addr.sin_addr);
int nsent = sendto(fd, buffer.pointer(), buffer.size(), 0, (const struct sockaddr*)&dst_addr, sizeof(dst_addr));
int nsent = sendto(fd, buffer.data(), buffer.size(), 0, (const struct sockaddr*)&dst_addr, sizeof(dst_addr));
if (nsent < 0) {
perror("sendto");
return {};

View file

@ -149,7 +149,7 @@ void Client::send_commands(Vector<Command> commands)
for (auto& command : commands)
stream << (u8)IAC << command.command << command.subcommand;
stream.snip();
m_socket->write(buffer.pointer(), buffer.size());
m_socket->write(buffer.data(), buffer.size());
}
void Client::quit()

View file

@ -820,7 +820,7 @@ void load_history()
while (history_file->can_read_line()) {
auto b = history_file->read_line(1024);
// skip the newline and terminating bytes
editor.add_to_history(String(reinterpret_cast<const char*>(b.pointer()), b.size() - 2));
editor.add_to_history(String(reinterpret_cast<const char*>(b.data()), b.size() - 2));
}
}

View file

@ -129,7 +129,7 @@ Result benchmark(const String& filename, int file_size, int block_size, ByteBuff
timer.start();
int nwrote = 0;
for (int j = 0; j < file_size; j += block_size) {
int n = write(fd, buffer.pointer(), block_size);
int n = write(fd, buffer.data(), block_size);
if (n < 0) {
perror("write");
cleanup_and_exit();
@ -146,7 +146,7 @@ Result benchmark(const String& filename, int file_size, int block_size, ByteBuff
timer.start();
int nread = 0;
while (nread < file_size) {
int n = read(fd, buffer.pointer(), block_size);
int n = read(fd, buffer.data(), block_size);
if (n < 0) {
perror("read");
cleanup_and_exit();

View file

@ -27,7 +27,7 @@ static String read_var(const String& name)
fprintf(stderr, "read: %s", f->error_string());
exit(1);
}
return String((const char*)b.pointer(), b.size(), Chomp);
return String((const char*)b.data(), b.size(), Chomp);
}
static void write_var(const String& name, const String& value)

View file

@ -28,7 +28,7 @@ int tail_from_pos(CFile& file, off_t startline, bool want_follow)
}
}
if (write(STDOUT_FILENO, b.pointer(), b.size()) < 0)
if (write(STDOUT_FILENO, b.data(), b.size()) < 0)
return 1;
}
@ -57,7 +57,7 @@ off_t find_seek_pos(CFile& file, int wanted_lines)
// Presumably the file got truncated?
// Keep trying to read backwards...
} else {
if (*ch.pointer() == '\n' && (end - pos) > 1) {
if (*ch.data() == '\n' && (end - pos) > 1) {
lines++;
if (lines == wanted_lines)
break;