diff --git a/libGraphite/data/data.cpp b/libGraphite/data/data.cpp index 85c3e3d..0cc8063 100644 --- a/libGraphite/data/data.cpp +++ b/libGraphite/data/data.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "libGraphite/data/data.hpp" #include "libGraphite/data/simd.hpp" @@ -291,21 +292,7 @@ __attribute__((optnone)) auto graphite::data::block::copy_from(const block &sour m_extended = source.m_extended; std::size_t len = std::min(source.size(), size()); - std::size_t n = 0; - while (n < len) { - if ((reinterpret_cast(source_ptr) & simd::alignment_width) || (len - n) < simd::fields_length) { - *dest_ptr = *source_ptr; - ++dest_ptr; - ++source_ptr; - n += simd::field_size; - } - else { - *reinterpret_cast(dest_ptr) = *reinterpret_cast(source_ptr); - dest_ptr += simd::field_count; - source_ptr += simd::field_count; - n += simd::alignment_width; - } - } + memcpy(dest_ptr, source_ptr, len); } // MARK: - Operations @@ -313,23 +300,20 @@ __attribute__((optnone)) auto graphite::data::block::copy_from(const block &sour auto graphite::data::block::increase_size_to(std::size_t new_size) -> void { if (new_size > m_raw_size) { - throw std::runtime_error("Attempted to increase size of data::block beyond allowed range."); + m_raw_size = std::max(m_data_size * 2, new_size); + m_raw = m_data = realloc(m_raw, m_raw_size); } m_data_size = new_size; } auto graphite::data::block::clear() -> void { - set((uint32_t)0); + set((uint8_t)0, size()); } auto graphite::data::block::set(uint8_t value, std::size_t bytes, block::position start) -> void { - union simd::value v; - for (unsigned char & byte : v.bytes) { - byte = value; - } - simd::set(get(start), size() - start, v, bytes); + memset(get(start), value, bytes); } __attribute__((optnone)) auto graphite::data::block::set(uint16_t value, std::size_t bytes, block::position start) -> void diff --git a/libGraphite/data/writer.cpp b/libGraphite/data/writer.cpp index 05439c1..083d5ca 100644 --- a/libGraphite/data/writer.cpp +++ b/libGraphite/data/writer.cpp @@ -57,21 +57,7 @@ auto graphite::data::writer::expand_storage(std::size_t amount) -> void // NOTE: We only allow resizing of data objects that we own. assert(m_owns_data); - // Construct a new data object with the appropriate new size, and copy in the old data. - auto required_size = size() + amount; - if (required_size < m_data->raw_size()) { - const_cast(m_data)->increase_size_to(required_size); - } - else { - auto allocation_size = size() + std::max(size(), amount); - auto new_data = new class block(required_size, std::max(allocation_size, required_size), m_data->byte_order()); - new_data->set(static_cast(0), allocation_size); - new_data->copy_from(*m_data); - - // Replace the old data with the new object. - delete m_data; - m_data = new_data; - } + const_cast(m_data)->increase_size_to(size() + amount); } @@ -232,4 +218,4 @@ auto graphite::data::writer::save(const std::string &path, std::size_t size) con std::ofstream file { path, std::ios::out | std::ios::binary }; file.write(m_data->get(), size == 0 ? m_data->size() : size); file.close(); -} \ No newline at end of file +} diff --git a/libGraphite/quickdraw/support/surface.cpp b/libGraphite/quickdraw/support/surface.cpp index 4769415..8b5230e 100644 --- a/libGraphite/quickdraw/support/surface.cpp +++ b/libGraphite/quickdraw/support/surface.cpp @@ -27,7 +27,7 @@ graphite::quickdraw::surface::surface(const quickdraw::size &size) m_row_bytes(size.width * constants::color_width), m_data(new data::block(size.width * size.height * constants::color_width)) { - m_data->set(static_cast(0), m_data->size()); + m_data->clear(); } graphite::quickdraw::surface::surface(std::int16_t width, std::int16_t height) @@ -35,7 +35,7 @@ graphite::quickdraw::surface::surface(std::int16_t width, std::int16_t height) m_row_bytes(width * constants::color_width), m_data(new data::block(width * height * constants::color_width)) { - m_data->set(static_cast(0), m_data->size()); + m_data->clear(); } graphite::quickdraw::surface::surface(const quickdraw::size& size, union color color) @@ -157,5 +157,5 @@ auto graphite::quickdraw::surface::set(std::uint32_t offset, union color color) auto graphite::quickdraw::surface::clear() -> void { - m_data->set(colors::clear().value, m_data->size()); -} \ No newline at end of file + m_data->clear(); +} diff --git a/libGraphite/spriteworld/rleD.cpp b/libGraphite/spriteworld/rleD.cpp index 16195d7..8f9cf83 100644 --- a/libGraphite/spriteworld/rleD.cpp +++ b/libGraphite/spriteworld/rleD.cpp @@ -173,7 +173,7 @@ auto graphite::spriteworld::rleD::decode(data::reader &reader) -> void // Create the surface in which all frame will be draw to, and other working variables required to parse and decode // the RLE data correctly. - m_surface = quickdraw::surface(m_grid_size.width * m_frame_size.width, m_grid_size.height * m_frame_size.height, quickdraw::colors::clear()); + m_surface = quickdraw::surface(m_grid_size.width * m_frame_size.width, m_grid_size.height * m_frame_size.height); rleD::opcode opcode = opcode::eof; std::uint64_t position = 0; @@ -383,4 +383,4 @@ auto graphite::spriteworld::rleD::encode(data::writer &writer) -> void writer.write_enum(opcode::eof); writer.write_triple(0); } -} \ No newline at end of file +} diff --git a/libGraphite/spriteworld/rleX.cpp b/libGraphite/spriteworld/rleX.cpp index d8b1cff..f2d2b85 100644 --- a/libGraphite/spriteworld/rleX.cpp +++ b/libGraphite/spriteworld/rleX.cpp @@ -326,7 +326,7 @@ auto graphite::spriteworld::rleX::decode(data::reader &reader) -> void // Create the surface in which all frames will be drawn to, and other working variables required to parse and // decode the RLE data correctly. - m_surface = quickdraw::surface(dim * m_frame_size.width, dim * m_frame_size.height, quickdraw::colors::clear()); + m_surface = quickdraw::surface(dim * m_frame_size.width, dim * m_frame_size.height); std::uint32_t current_frame = 0; std::uint32_t count = 0;