1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Improved byte write speed by a lot

This commit is contained in:
WerWolv 2020-11-27 13:44:52 +01:00
parent fde9dc7961
commit 015ec12215
5 changed files with 13 additions and 12 deletions

View File

@ -6,6 +6,7 @@
namespace hex {
enum class Events {
FileLoaded,
DataChanged,
PatternChanged,
FileDropped,

View File

@ -18,10 +18,10 @@ namespace hex::prv {
bool isWritable() override;
void read(u64 offset, void *buffer, size_t size) override;
void write(u64 offset, void *buffer, size_t size) override;
void write(u64 offset, const void *buffer, size_t size) override;
void readRaw(u64 offset, void *buffer, size_t size) override;
void writeRaw(u64 offset, void *buffer, size_t size) override;
void writeRaw(u64 offset, const void *buffer, size_t size) override;
size_t getActualSize() override;
std::vector<std::pair<std::string, std::string>> getDataInformation() override;

View File

@ -26,10 +26,10 @@ namespace hex::prv {
virtual bool isWritable() = 0;
virtual void read(u64 offset, void *buffer, size_t size) { this->readRaw(offset, buffer, size); }
virtual void write(u64 offset, void *buffer, size_t size) { this->writeRaw(offset, buffer, size); }
virtual void write(u64 offset, const void *buffer, size_t size) { this->writeRaw(offset, buffer, size); }
virtual void readRaw(u64 offset, void *buffer, size_t size) = 0;
virtual void writeRaw(u64 offset, void *buffer, size_t size) = 0;
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
virtual size_t getActualSize() = 0;
const std::map<u64, u8>& getPatches() { return this->m_patches.back(); }

View File

@ -48,23 +48,23 @@ namespace hex::prv {
return;
fseeko64(this->m_file, this->getCurrentPage() * PageSize + offset, SEEK_SET);
fread(buffer, 1, size, this->m_file);
size_t readSize = fread(buffer, 1, size, this->m_file);
for (u64 i = 0; i < size; i++)
for (u64 i = 0; i < readSize; i++)
if (this->m_patches.back().contains(offset + i))
reinterpret_cast<u8*>(buffer)[i] = this->m_patches.back()[offset + i];
}
void FileProvider::write(u64 offset, void *buffer, size_t size) {
void FileProvider::write(u64 offset, const void *buffer, size_t size) {
if (buffer == nullptr || size == 0)
return;
this->m_patches.push_back(this->m_patches.back());
for (u64 i = 0; i < size; i++)
this->m_patches.back()[offset + i] = reinterpret_cast<u8*>(buffer)[i];
this->m_patches.back()[offset + i] = reinterpret_cast<const u8*>(buffer)[i];
}
void FileProvider::readRaw(u64 offset, void *buffer, size_t size) {
@ -75,12 +75,12 @@ namespace hex::prv {
fread(buffer, 1, size, this->m_file);
}
void FileProvider::writeRaw(u64 offset, void *buffer, size_t size) {
void FileProvider::writeRaw(u64 offset, const void *buffer, size_t size) {
if (buffer == nullptr || size == 0)
return;
fseeko64(this->m_file, offset, SEEK_SET);
fwrite(&buffer, 1, size, this->m_file);
fwrite(buffer, 1, size, this->m_file);
}
size_t FileProvider::getActualSize() {
fseeko64(this->m_file, 0, SEEK_END);

View File

@ -74,7 +74,7 @@ namespace hex {
this->m_textEditor.SetLanguageDefinition(PatternLanguage());
this->m_textEditor.SetShowWhitespaces(false);
View::subscribeEvent(Events::DataChanged, [this](const void* userData) {
View::subscribeEvent(Events::FileLoaded, [this](const void* userData) {
lang::Preprocessor preprocessor;
std::string magicFiles;
@ -85,7 +85,7 @@ namespace hex {
magicFiles += entry.path().string() + MAGIC_PATH_SEPARATOR;
}
std::vector<u8> buffer(std::min(this->m_dataProvider->getSize(), size_t(0xFF'FFFF)), 0x00);
std::vector<u8> buffer(std::min(this->m_dataProvider->getSize(), size_t(0xFFFF)), 0x00);
this->m_dataProvider->read(0, buffer.data(), buffer.size());
std::string mimeType;