Use "" to indicate the oat filename could not be computed.
Instead of having an extra boolean flag.
Test: oat file assistant tests.
Change-Id: I91249ba862522e691c6b67fd28a2eac58dcde07e
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 046c80e..aae9d97 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -87,7 +87,6 @@
if (oat_location != nullptr) {
cached_oat_file_name_ = std::string(oat_location);
cached_oat_file_name_attempted_ = true;
- cached_oat_file_name_found_ = true;
}
}
@@ -357,15 +356,13 @@
cached_odex_file_name_attempted_ = true;
std::string error_msg;
- cached_odex_file_name_found_ = DexFilenameToOdexFilename(
- dex_location_, isa_, &cached_odex_file_name_, &error_msg);
- if (!cached_odex_file_name_found_) {
+ if (!DexFilenameToOdexFilename(dex_location_, isa_, &cached_odex_file_name_, &error_msg)) {
// If we can't figure out the odex file, we treat it as if the odex
// file was inaccessible.
LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
}
}
- return cached_odex_file_name_found_ ? &cached_odex_file_name_ : nullptr;
+ return cached_odex_file_name_.empty() ? nullptr : &cached_odex_file_name_;
}
bool OatFileAssistant::OdexFileExists() {
@@ -426,16 +423,15 @@
std::string cache_dir = StringPrintf("%s%s",
DalvikCacheDirectory().c_str(), GetInstructionSetString(isa_));
std::string error_msg;
- cached_oat_file_name_found_ = GetDalvikCacheFilename(dex_location_.c_str(),
- cache_dir.c_str(), &cached_oat_file_name_, &error_msg);
- if (!cached_oat_file_name_found_) {
+ if (!GetDalvikCacheFilename(dex_location_.c_str(),
+ cache_dir.c_str(), &cached_oat_file_name_, &error_msg)) {
// If we can't determine the oat file name, we treat the oat file as
// inaccessible.
LOG(WARNING) << "Failed to determine oat file name for dex location "
<< dex_location_ << ": " << error_msg;
}
}
- return cached_oat_file_name_found_ ? &cached_oat_file_name_ : nullptr;
+ return cached_oat_file_name_.empty() ? nullptr : &cached_oat_file_name_;
}
bool OatFileAssistant::OatFileExists() {
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index e706a30..e4aba3f 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -277,7 +277,8 @@
// Constructs the odex file name for the given dex location.
// Returns true on success, in which case odex_filename is set to the odex
// file name.
- // Returns false on error, in which case error_msg describes the error.
+ // Returns false on error, in which case error_msg describes the error and
+ // odex_filename is not changed.
// Neither odex_filename nor error_msg may be null.
static bool DexFilenameToOdexFilename(const std::string& location,
InstructionSet isa, std::string* odex_filename, std::string* error_msg);
@@ -384,8 +385,9 @@
// Cached value of the odex file name.
// This should be accessed only by the OdexFileName() method.
+ // The sentinel value "" is used if the odex file name could not be
+ // determined.
bool cached_odex_file_name_attempted_ = false;
- bool cached_odex_file_name_found_;
std::string cached_odex_file_name_;
// Cached value of the loaded odex file.
@@ -400,8 +402,9 @@
// Cached value of the oat file name.
// This should be accessed only by the OatFileName() method.
+ // The sentinel value "" is used if the oat file name could not be
+ // determined.
bool cached_oat_file_name_attempted_ = false;
- bool cached_oat_file_name_found_;
std::string cached_oat_file_name_;
// Cached value of the loaded oat file.