mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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:
parent
b2d0f9eefd
commit
5986e9f639
@ -814,8 +814,7 @@ folly::Future<struct stat> FileInode::stat() {
|
||||
// state->tag is either MATERIALIZED_IN_OVERLAY or BLOB_LOADED.
|
||||
DCHECK_EQ(state->tag, State::BLOB_LOADED);
|
||||
CHECK(state->blob);
|
||||
auto buf = state->blob->getContents();
|
||||
st.st_size = buf.computeChainDataLength();
|
||||
st.st_size = state->blob->getSize();
|
||||
|
||||
// NOTE: we don't set rdev to anything special here because we
|
||||
// don't support committing special device nodes.
|
||||
|
@ -19,10 +19,14 @@ namespace eden {
|
||||
class Blob {
|
||||
public:
|
||||
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)
|
||||
: hash_(hash), contents_(contents) {}
|
||||
: hash_{hash},
|
||||
contents_{contents},
|
||||
size_{contents_.computeChainDataLength()} {}
|
||||
|
||||
const Hash& getHash() const {
|
||||
return hash_;
|
||||
@ -32,9 +36,14 @@ class Blob {
|
||||
return contents_;
|
||||
}
|
||||
|
||||
size_t getSize() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
private:
|
||||
const Hash hash_;
|
||||
const folly::IOBuf contents_;
|
||||
const size_t size_;
|
||||
};
|
||||
} // namespace eden
|
||||
} // namespace facebook
|
||||
|
Loading…
Reference in New Issue
Block a user