Use Rust Filename comparisons for C++ Filename operators

To prevent inconsistencies between implementations. This means allocating new boxed Filenames for each comparison, but an extra string copy is avoided by making the C++ operators friends of the C++ class (which is ABI-safe).
This commit is contained in:
Oliver Hamlet
2025-05-05 11:45:50 +01:00
parent eabc7a5d85
commit 1317eea055
6 changed files with 21 additions and 16 deletions
+4 -2
View File
@@ -35,7 +35,8 @@ Filename::Filename(std::string_view filename) : filename_(filename) {}
Filename::operator std::string() const { return filename_; }
bool operator==(const Filename& lhs, const Filename& rhs) {
return loot::rust::compare_filenames(std::string(lhs), std::string(rhs)) == 0;
return loot::rust::new_filename(lhs.filename_)
->eq(*loot::rust::new_filename(rhs.filename_));
}
bool operator!=(const Filename& lhs, const Filename& rhs) {
@@ -43,7 +44,8 @@ bool operator!=(const Filename& lhs, const Filename& rhs) {
}
bool operator<(const Filename& lhs, const Filename& rhs) {
return loot::rust::compare_filenames(std::string(lhs), std::string(rhs)) < 0;
return loot::rust::new_filename(lhs.filename_)
->lt(*loot::rust::new_filename(rhs.filename_));
}
bool operator>(const Filename& lhs, const Filename& rhs) { return rhs < lhs; }