diff --git a/lib/marisa/keyset.cc b/lib/marisa/keyset.cc index 41354f7..03e621b 100644 --- a/lib/marisa/keyset.cc +++ b/lib/marisa/keyset.cc @@ -1,3 +1,4 @@ +#include #include #include "marisa/keyset.h" @@ -14,9 +15,7 @@ void Keyset::push_back(const Key &key) { MARISA_DEBUG_IF(size_ == MARISA_SIZE_MAX, MARISA_SIZE_ERROR); char * const key_ptr = reserve(key.length()); - for (std::size_t i = 0; i < key.length(); ++i) { - key_ptr[i] = key[i]; - } + std::memcpy(key_ptr, key.ptr(), key.length()); Key &new_key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; new_key.set_str(key_ptr, key.length()); @@ -33,9 +32,7 @@ void Keyset::push_back(const Key &key, char end_marker) { } char * const key_ptr = reserve(key.length() + 1); - for (std::size_t i = 0; i < key.length(); ++i) { - key_ptr[i] = key[i]; - } + std::memcpy(key_ptr, key.ptr(), key.length()); key_ptr[key.length()] = end_marker; Key &new_key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; @@ -62,9 +59,7 @@ void Keyset::push_back(const char *ptr, std::size_t length, float weight) { MARISA_THROW_IF(length > MARISA_UINT32_MAX, MARISA_SIZE_ERROR); char * const key_ptr = reserve(length); - for (std::size_t i = 0; i < length; ++i) { - key_ptr[i] = ptr[i]; - } + std::memcpy(key_ptr, ptr, length); Key &key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; key.set_str(key_ptr, length);