strat: use m_ for member variables
This commit is contained in:
@@ -68,22 +68,22 @@ namespace ams::kvdb {
|
||||
/* Reader functionality. */
|
||||
Result ArchiveReader::Peek(void *dst, size_t size) {
|
||||
/* Bounds check. */
|
||||
R_UNLESS(this->offset + size <= this->buffer.GetSize(), kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(this->offset < this->offset + size, kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(m_offset + size <= m_buffer.GetSize(), kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(m_offset < m_offset + size, kvdb::ResultInvalidKeyValue());
|
||||
|
||||
std::memcpy(dst, this->buffer.Get() + this->offset, size);
|
||||
std::memcpy(dst, m_buffer.Get() + m_offset, size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ArchiveReader::Read(void *dst, size_t size) {
|
||||
R_TRY(this->Peek(dst, size));
|
||||
this->offset += size;
|
||||
m_offset += size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ArchiveReader::ReadEntryCount(size_t *out) {
|
||||
/* This should only be called at the start of reading stream. */
|
||||
AMS_ABORT_UNLESS(this->offset == 0);
|
||||
AMS_ABORT_UNLESS(m_offset == 0);
|
||||
|
||||
/* Read and validate header. */
|
||||
ArchiveHeader header;
|
||||
@@ -96,7 +96,7 @@ namespace ams::kvdb {
|
||||
|
||||
Result ArchiveReader::GetEntrySize(size_t *out_key_size, size_t *out_value_size) {
|
||||
/* This should only be called after ReadEntryCount. */
|
||||
AMS_ABORT_UNLESS(this->offset != 0);
|
||||
AMS_ABORT_UNLESS(m_offset != 0);
|
||||
|
||||
/* Peek the next entry header. */
|
||||
ArchiveEntryHeader header;
|
||||
@@ -110,7 +110,7 @@ namespace ams::kvdb {
|
||||
|
||||
Result ArchiveReader::ReadEntry(void *out_key, size_t key_size, void *out_value, size_t value_size) {
|
||||
/* This should only be called after ReadEntryCount. */
|
||||
AMS_ABORT_UNLESS(this->offset != 0);
|
||||
AMS_ABORT_UNLESS(m_offset != 0);
|
||||
|
||||
/* Read the next entry header. */
|
||||
ArchiveEntryHeader header;
|
||||
@@ -129,17 +129,17 @@ namespace ams::kvdb {
|
||||
/* Writer functionality. */
|
||||
Result ArchiveWriter::Write(const void *src, size_t size) {
|
||||
/* Bounds check. */
|
||||
R_UNLESS(this->offset + size <= this->buffer.GetSize(), kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(this->offset < this->offset + size, kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(m_offset + size <= m_buffer.GetSize(), kvdb::ResultInvalidKeyValue());
|
||||
R_UNLESS(m_offset < m_offset + size, kvdb::ResultInvalidKeyValue());
|
||||
|
||||
std::memcpy(this->buffer.Get() + this->offset, src, size);
|
||||
this->offset += size;
|
||||
std::memcpy(m_buffer.Get() + m_offset, src, size);
|
||||
m_offset += size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void ArchiveWriter::WriteHeader(size_t entry_count) {
|
||||
/* This should only be called at start of write. */
|
||||
AMS_ABORT_UNLESS(this->offset == 0);
|
||||
AMS_ABORT_UNLESS(m_offset == 0);
|
||||
|
||||
ArchiveHeader header = ArchiveHeader::Make(entry_count);
|
||||
R_ABORT_UNLESS(this->Write(std::addressof(header), sizeof(header)));
|
||||
@@ -147,7 +147,7 @@ namespace ams::kvdb {
|
||||
|
||||
void ArchiveWriter::WriteEntry(const void *key, size_t key_size, const void *value, size_t value_size) {
|
||||
/* This should only be called after writing header. */
|
||||
AMS_ABORT_UNLESS(this->offset != 0);
|
||||
AMS_ABORT_UNLESS(m_offset != 0);
|
||||
|
||||
ArchiveEntryHeader header = ArchiveEntryHeader::Make(key_size, value_size);
|
||||
R_ABORT_UNLESS(this->Write(std::addressof(header), sizeof(header)));
|
||||
@@ -156,12 +156,12 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
/* Size helper functionality. */
|
||||
ArchiveSizeHelper::ArchiveSizeHelper() : size(sizeof(ArchiveHeader)) {
|
||||
ArchiveSizeHelper::ArchiveSizeHelper() : m_size(sizeof(ArchiveHeader)) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
void ArchiveSizeHelper::AddEntry(size_t key_size, size_t value_size) {
|
||||
this->size += sizeof(ArchiveEntryHeader) + key_size + value_size;
|
||||
m_size += sizeof(ArchiveEntryHeader) + key_size + value_size;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,25 +19,25 @@ namespace ams::kvdb {
|
||||
|
||||
/* Cache implementation. */
|
||||
void *FileKeyValueStore::Cache::Allocate(size_t size) {
|
||||
if (this->backing_buffer_size - this->backing_buffer_free_offset < size) {
|
||||
if (m_backing_buffer_size - m_backing_buffer_free_offset < size) {
|
||||
return nullptr;
|
||||
}
|
||||
ON_SCOPE_EXIT { this->backing_buffer_free_offset += size; };
|
||||
return this->backing_buffer + this->backing_buffer_free_offset;
|
||||
ON_SCOPE_EXIT { m_backing_buffer_free_offset += size; };
|
||||
return m_backing_buffer + m_backing_buffer_free_offset;
|
||||
}
|
||||
|
||||
Result FileKeyValueStore::Cache::Initialize(void *buffer, size_t buffer_size, size_t capacity) {
|
||||
this->backing_buffer = static_cast<u8 *>(buffer);
|
||||
this->backing_buffer_size = buffer_size;
|
||||
this->backing_buffer_free_offset = 0;
|
||||
this->entries = nullptr;
|
||||
this->count = 0;
|
||||
this->capacity = capacity;
|
||||
m_backing_buffer = static_cast<u8 *>(buffer);
|
||||
m_backing_buffer_size = buffer_size;
|
||||
m_backing_buffer_free_offset = 0;
|
||||
m_entries = nullptr;
|
||||
m_count = 0;
|
||||
m_capacity = capacity;
|
||||
|
||||
/* If we have memory to work with, ensure it's at least enough for the cache entries. */
|
||||
if (this->backing_buffer != nullptr) {
|
||||
this->entries = static_cast<decltype(this->entries)>(this->Allocate(sizeof(*this->entries) * this->capacity));
|
||||
R_UNLESS(this->entries != nullptr, kvdb::ResultBufferInsufficient());
|
||||
if (m_backing_buffer != nullptr) {
|
||||
m_entries = static_cast<decltype(m_entries)>(this->Allocate(sizeof(*m_entries) * m_capacity));
|
||||
R_UNLESS(m_entries != nullptr, kvdb::ResultBufferInsufficient());
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -49,10 +49,10 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
/* Reset the allocation pool. */
|
||||
this->backing_buffer_free_offset = 0;
|
||||
this->count = 0;
|
||||
this->entries = static_cast<decltype(this->entries)>(this->Allocate(sizeof(*this->entries) * this->capacity));
|
||||
AMS_ABORT_UNLESS(this->entries != nullptr);
|
||||
m_backing_buffer_free_offset = 0;
|
||||
m_count = 0;
|
||||
m_entries = static_cast<decltype(m_entries)>(this->Allocate(sizeof(*m_entries) * m_capacity));
|
||||
AMS_ABORT_UNLESS(m_entries != nullptr);
|
||||
}
|
||||
|
||||
util::optional<size_t> FileKeyValueStore::Cache::TryGet(void *out_value, size_t max_out_size, const void *key, size_t key_size) {
|
||||
@@ -61,8 +61,8 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
/* Try to find the entry. */
|
||||
for (size_t i = 0; i < this->count; i++) {
|
||||
const auto &entry = this->entries[i];
|
||||
for (size_t i = 0; i < m_count; i++) {
|
||||
const auto &entry = m_entries[i];
|
||||
if (entry.key_size == key_size && std::memcmp(entry.key, key, key_size) == 0) {
|
||||
/* If we don't have enough space, fail to read from cache. */
|
||||
if (max_out_size < entry.value_size) {
|
||||
@@ -83,8 +83,8 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
/* Try to find the entry. */
|
||||
for (size_t i = 0; i < this->count; i++) {
|
||||
const auto &entry = this->entries[i];
|
||||
for (size_t i = 0; i < m_count; i++) {
|
||||
const auto &entry = m_entries[i];
|
||||
if (entry.key_size == key_size && std::memcmp(entry.key, key, key_size) == 0) {
|
||||
return entry.value_size;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace ams::kvdb {
|
||||
AMS_ABORT_UNLESS(key_size <= MaxKeySize);
|
||||
|
||||
/* If we're at capacity, invalidate the cache. */
|
||||
if (this->count == this->capacity) {
|
||||
if (m_count == m_capacity) {
|
||||
this->Invalidate();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace ams::kvdb {
|
||||
}
|
||||
}
|
||||
|
||||
auto &entry = this->entries[this->count++];
|
||||
auto &entry = m_entries[m_count++];
|
||||
std::memcpy(entry.key, key, key_size);
|
||||
entry.key_size = key_size;
|
||||
entry.value = value_buf;
|
||||
@@ -133,7 +133,7 @@ namespace ams::kvdb {
|
||||
/* Store functionality. */
|
||||
FileKeyValueStore::Path FileKeyValueStore::GetPath(const void *_key, size_t key_size) {
|
||||
/* Format is "<dir>/<hex formatted key>.val" */
|
||||
FileKeyValueStore::Path key_path(this->dir_path.Get());
|
||||
FileKeyValueStore::Path key_path(m_dir_path.Get());
|
||||
key_path.Append('/');
|
||||
|
||||
/* Append hex formatted key. */
|
||||
@@ -184,22 +184,22 @@ namespace ams::kvdb {
|
||||
R_UNLESS(entry_type == fs::DirectoryEntryType_Directory, fs::ResultPathNotFound());
|
||||
|
||||
/* Set path. */
|
||||
this->dir_path.Set(dir);
|
||||
m_dir_path.Set(dir);
|
||||
|
||||
/* Initialize our cache. */
|
||||
R_TRY(this->cache.Initialize(cache_buffer, cache_buffer_size, cache_capacity));
|
||||
R_TRY(m_cache.Initialize(cache_buffer, cache_buffer_size, cache_capacity));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileKeyValueStore::Get(size_t *out_size, void *out_value, size_t max_out_size, const void *key, size_t key_size) {
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
/* Ensure key size is small enough. */
|
||||
R_UNLESS(key_size <= MaxKeySize, kvdb::ResultOutOfKeyResource());
|
||||
|
||||
/* Try to get from cache. */
|
||||
{
|
||||
auto size = this->cache.TryGet(out_value, max_out_size, key, key_size);
|
||||
auto size = m_cache.TryGet(out_value, max_out_size, key, key_size);
|
||||
if (size) {
|
||||
*out_size = *size;
|
||||
return ResultSuccess();
|
||||
@@ -226,19 +226,19 @@ namespace ams::kvdb {
|
||||
*out_size = value_size;
|
||||
|
||||
/* Cache the newly read value. */
|
||||
this->cache.Set(key, key_size, out_value, value_size);
|
||||
m_cache.Set(key, key_size, out_value, value_size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileKeyValueStore::GetSize(size_t *out_size, const void *key, size_t key_size) {
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
/* Ensure key size is small enough. */
|
||||
R_UNLESS(key_size <= MaxKeySize, kvdb::ResultOutOfKeyResource());
|
||||
|
||||
/* Try to get from cache. */
|
||||
{
|
||||
auto size = this->cache.TryGetSize(key, key_size);
|
||||
auto size = m_cache.TryGetSize(key, key_size);
|
||||
if (size) {
|
||||
*out_size = *size;
|
||||
return ResultSuccess();
|
||||
@@ -261,14 +261,14 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
Result FileKeyValueStore::Set(const void *key, size_t key_size, const void *value, size_t value_size) {
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
/* Ensure key size is small enough. */
|
||||
R_UNLESS(key_size <= MaxKeySize, kvdb::ResultOutOfKeyResource());
|
||||
|
||||
/* When the cache contains the key being set, Nintendo invalidates the cache. */
|
||||
if (this->cache.Contains(key, key_size)) {
|
||||
this->cache.Invalidate();
|
||||
if (m_cache.Contains(key, key_size)) {
|
||||
m_cache.Invalidate();
|
||||
}
|
||||
|
||||
/* Delete the file, if it exists. Don't check result, since it's okay if it's already deleted. */
|
||||
@@ -290,14 +290,14 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
Result FileKeyValueStore::Remove(const void *key, size_t key_size) {
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
/* Ensure key size is small enough. */
|
||||
R_UNLESS(key_size <= MaxKeySize, kvdb::ResultOutOfKeyResource());
|
||||
|
||||
/* When the cache contains the key being set, Nintendo invalidates the cache. */
|
||||
if (this->cache.Contains(key, key_size)) {
|
||||
this->cache.Invalidate();
|
||||
if (m_cache.Contains(key, key_size)) {
|
||||
m_cache.Invalidate();
|
||||
}
|
||||
|
||||
/* Remove the file. */
|
||||
|
||||
Reference in New Issue
Block a user