return fd_is_on_known_to_work_file_system(fd);
}
-bool
-InodeCache::get(const std::string& path,
- ContentType type,
- Digest& file_digest,
- HashSourceCodeResult* return_value)
+std::optional<HashSourceCodeResult>
+InodeCache::get(const std::string& path, ContentType type, Digest& file_digest)
{
if (!initialize()) {
- return false;
+ return std::nullopt;
}
Digest key_digest;
if (!hash_inode(path, type, key_digest)) {
- return false;
+ return std::nullopt;
}
- bool found = false;
+ std::optional<HashSourceCodeResult> result;
const bool success = with_bucket(key_digest, [&](const auto bucket) {
for (uint32_t i = 0; i < k_num_entries; ++i) {
if (bucket->entries[i].key_digest == key_digest) {
}
file_digest = bucket->entries[0].file_digest;
- if (return_value) {
- *return_value =
- HashSourceCodeResult::from_bitmask(bucket->entries[0].return_value);
- }
- found = true;
+ result =
+ HashSourceCodeResult::from_bitmask(bucket->entries[0].return_value);
break;
}
}
});
if (!success) {
- return false;
+ return std::nullopt;
}
if (m_config.debug()) {
- LOG("Inode cache {}: {}", found ? "hit" : "miss", path);
- if (found) {
+ LOG("Inode cache {}: {}", result ? "hit" : "miss", path);
+ if (result) {
++m_sr->hits;
} else {
++m_sr->misses;
}
}
- return found;
+ return result;
}
bool
InodeCache inode_cache(config, util::Duration(0));
Digest digest;
- HashSourceCodeResult return_value;
- CHECK(!inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ CHECK(!inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest));
CHECK(!inode_cache.put("a",
InodeCache::ContentType::checked_for_temporal_macros,
digest,
- return_value));
+ HashSourceCodeResult()));
CHECK(inode_cache.get_hits() == -1);
CHECK(inode_cache.get_misses() == -1);
CHECK(inode_cache.get_errors() == -1);
util::write_file("a", "");
Digest digest;
- HashSourceCodeResult return_value;
- CHECK(!inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ CHECK(!inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest));
CHECK(inode_cache.get_hits() == 0);
CHECK(inode_cache.get_misses() == 1);
CHECK(inode_cache.get_errors() == 0);
CHECK(put(inode_cache, "a", "a text", result));
Digest digest;
- HashSourceCodeResult return_value;
-
- CHECK(inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ auto return_value = inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest);
+ REQUIRE(return_value);
CHECK(digest == Hash().hash("a text").digest());
- CHECK(return_value.to_bitmask()
+ CHECK(return_value->to_bitmask()
== static_cast<int>(HashSourceCode::found_date));
CHECK(inode_cache.get_hits() == 1);
CHECK(inode_cache.get_misses() == 0);
util::write_file("a", "something else");
- CHECK(!inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ CHECK(!inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest));
CHECK(inode_cache.get_hits() == 1);
CHECK(inode_cache.get_misses() == 1);
CHECK(inode_cache.get_errors() == 0);
"something else",
HashSourceCodeResult(HashSourceCode::found_time)));
- CHECK(inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ return_value = inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest);
+ REQUIRE(return_value);
CHECK(digest == Hash().hash("something else").digest());
- CHECK(return_value.to_bitmask()
+ CHECK(return_value->to_bitmask()
== static_cast<int>(HashSourceCode::found_time));
CHECK(inode_cache.get_hits() == 2);
CHECK(inode_cache.get_misses() == 1);
HashSourceCodeResult(HashSourceCode::found_time)));
Digest digest;
- HashSourceCodeResult return_value;
- CHECK(
- inode_cache.get("a", InodeCache::ContentType::raw, digest, &return_value));
+ auto return_value =
+ inode_cache.get("a", InodeCache::ContentType::raw, digest);
+ REQUIRE(return_value);
CHECK(digest == binary_digest);
- CHECK(return_value.to_bitmask()
+ CHECK(return_value->to_bitmask()
== static_cast<int>(HashSourceCode::found_date));
- CHECK(inode_cache.get("a",
- InodeCache::ContentType::checked_for_temporal_macros,
- digest,
- &return_value));
+ return_value = inode_cache.get(
+ "a", InodeCache::ContentType::checked_for_temporal_macros, digest);
+ REQUIRE(return_value);
CHECK(digest == code_digest);
- CHECK(return_value.to_bitmask()
+ CHECK(return_value->to_bitmask()
== static_cast<int>(HashSourceCode::found_time));
}