diff options
author | Peng Wu <alexepico@gmail.com> | 2022-11-29 16:33:03 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2022-11-29 16:33:03 +0800 |
commit | 0aa6b1dff140cd7bdc3f200752e1e9d8569680de (patch) | |
tree | 73ef86148744f9b853bb20d4c970928f86f21d36 | |
parent | df10f4f6f04cfe37e30b23e1da12dc3d2448559f (diff) | |
download | libpinyin-0aa6b1dff140cd7bdc3f200752e1e9d8569680de.tar.gz libpinyin-0aa6b1dff140cd7bdc3f200752e1e9d8569680de.tar.xz libpinyin-0aa6b1dff140cd7bdc3f200752e1e9d8569680de.zip |
Update class MemoryChunk
-rw-r--r-- | src/include/memory_chunk.h | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/include/memory_chunk.h b/src/include/memory_chunk.h index baa5679..713fb5c 100644 --- a/src/include/memory_chunk.h +++ b/src/include/memory_chunk.h @@ -33,6 +33,7 @@ #define LIBPINYIN_USE_MMAP #endif #include "stl_lite.h" +#include "pinyin_utils.h" namespace pinyin{ @@ -300,12 +301,7 @@ public: */ template <typename T> bool set_content(size_t offset, T data){ - const size_t len = sizeof(data); - size_t cursize = std_lite::max(size(), offset + len); - ensure_has_space(offset + len); - memmove(m_data_begin + offset, &data, len); - m_data_end = m_data_begin + cursize; - return true; + return set_content(offset, &data, sizeof(T)); } /** @@ -368,7 +364,7 @@ public: * Get the content in this MemoryChunk. * */ - bool get_content(size_t offset, void * buffer, size_t length){ + bool get_content(size_t offset, void * buffer, size_t length) const { if ( size() < offset + length ) return false; memcpy( buffer, m_data_begin + offset, length); @@ -386,7 +382,7 @@ public: template <typename T> T get_content(size_t offset) const { T value; - memcpy(&value, m_data_begin + offset, sizeof(value)); + check_result(get_content(offset, &value, sizeof(T))); return value; } |