Why leveldb uses two PutFixed32 to Encoding footer instead of one PutFixed64?

22 views Asked by At

Why does leveldb use two PutFixed32 instead of PutFixed64 directly in the process of encoding the magic number in the footer?

void Footer::EncodeTo(std::string* dst) const {
  const size_t original_size = dst->size();
  metaindex_handle_.EncodeTo(dst);
  index_handle_.EncodeTo(dst);
  dst->resize(2 * BlockHandle::kMaxEncodedLength);  // Padding
  PutFixed32(dst, static_cast<uint32_t>(kTableMagicNumber & 0xffffffffu));
  PutFixed32(dst, static_cast<uint32_t>(kTableMagicNumber >> 32));
...
}

It can be:

void Footer::EncodeTo(std::string* dst) const {
  const size_t original_size = dst->size();
  metaindex_handle_.EncodeTo(dst);
  index_handle_.EncodeTo(dst);
  dst->resize(2 * BlockHandle::kMaxEncodedLength);  // Padding
  PutFixed64(dst, kTableMagicNumber);
...
}

This way is more concise.

It's possible that using two PutFixed32 is faster than using one PutFixed64?

0

There are 0 answers