Skip to content

Commit

Permalink
convert values to const
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Jul 13, 2022
1 parent f4e5ecd commit bdd5da4
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ class TableWrapperOptimized final : public TableWrapperBase<K, V> {
const string tmp_file = filepath + ".tmp";
TF_RETURN_IF_ERROR(hdfs.NewWritableFile(tmp_file, &writer));

uint32 record_len = sizeof(K) + sizeof(V) * dim;
const uint32 value_len = sizeof(V) * dim;
const uint32 record_len = sizeof(K) + value_len;
uint64 pos = 0;
uint8 content[buffer_size + record_len];

Expand All @@ -268,7 +269,7 @@ class TableWrapperOptimized final : public TableWrapperBase<K, V> {

const auto& jt = it->second.data();
std::memcpy(content + pos + sizeof(K), reinterpret_cast<uint8*>(jt),
sizeof(V) * dim);
value_len);

pos += record_len;
if (pos > buffer_size) {
Expand Down Expand Up @@ -304,8 +305,10 @@ class TableWrapperOptimized final : public TableWrapperBase<K, V> {
TF_RETURN_IF_ERROR(hdfs.GetFileSize(filepath, &file_size));

tstring content;
uint64 record_len = sizeof(K) + sizeof(V) * dim;
const uint32 value_len = sizeof(V) * dim;
const uint32 record_len = sizeof(K) + value_len;
uint64 i = 0;

while (i < file_size) {
TF_RETURN_IF_ERROR(reader.ReadNBytes(record_len, &content));
K k;
Expand All @@ -314,7 +317,7 @@ class TableWrapperOptimized final : public TableWrapperBase<K, V> {
ValueType value_vec;
std::memcpy(value_vec.data(),
reinterpret_cast<uint8*>(content.data()) + sizeof(K),
sizeof(V) * dim);
value_len);
table_->insert_or_assign(k, value_vec);
i += record_len;
}
Expand Down

0 comments on commit bdd5da4

Please sign in to comment.