compute Blob size upon construction

Summary:
Add a direct getSize() accessor to Blob. The thinking here is that all
of this information is known and in cache when the Blob is
constructed, so there's no need to walk a list later on.

Reviewed By: simpkins

Differential Revision: D10245695

fbshipit-source-id: f6d5abbae75d468085dcc02bbbac8aa6239a7c70
This commit is contained in:
Chad Austin 2018-10-09 10:52:00 -07:00 committed by Facebook Github Bot
parent b2d0f9eefd
commit 5986e9f639
2 changed files with 12 additions and 4 deletions

View File

@ -814,8 +814,7 @@ folly::Future<struct stat> FileInode::stat() {
// state->tag is either MATERIALIZED_IN_OVERLAY or BLOB_LOADED. // state->tag is either MATERIALIZED_IN_OVERLAY or BLOB_LOADED.
DCHECK_EQ(state->tag, State::BLOB_LOADED); DCHECK_EQ(state->tag, State::BLOB_LOADED);
CHECK(state->blob); CHECK(state->blob);
auto buf = state->blob->getContents(); st.st_size = state->blob->getSize();
st.st_size = buf.computeChainDataLength();
// NOTE: we don't set rdev to anything special here because we // NOTE: we don't set rdev to anything special here because we
// don't support committing special device nodes. // don't support committing special device nodes.

View File

@ -19,10 +19,14 @@ namespace eden {
class Blob { class Blob {
public: public:
Blob(const Hash& hash, folly::IOBuf&& contents) Blob(const Hash& hash, folly::IOBuf&& contents)
: hash_(hash), contents_(std::move(contents)) {} : hash_{hash},
contents_{std::move(contents)},
size_{contents_.computeChainDataLength()} {}
Blob(const Hash& hash, const folly::IOBuf& contents) Blob(const Hash& hash, const folly::IOBuf& contents)
: hash_(hash), contents_(contents) {} : hash_{hash},
contents_{contents},
size_{contents_.computeChainDataLength()} {}
const Hash& getHash() const { const Hash& getHash() const {
return hash_; return hash_;
@ -32,9 +36,14 @@ class Blob {
return contents_; return contents_;
} }
size_t getSize() const {
return size_;
}
private: private:
const Hash hash_; const Hash hash_;
const folly::IOBuf contents_; const folly::IOBuf contents_;
const size_t size_;
}; };
} // namespace eden } // namespace eden
} // namespace facebook } // namespace facebook