================ @@ -0,0 +1,66 @@ +//===-- RealpathPrefixes.cpp ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/RealpathPrefixes.h" + +#include "lldb/Target/Statistics.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/FileSpecList.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +using namespace lldb_private; + +RealpathPrefixes::RealpathPrefixes(const FileSpecList &file_spec_list) + : m_fs(llvm::vfs::getRealFileSystem()), m_target(nullptr) { + m_prefixes.reserve(file_spec_list.GetSize()); + for (const FileSpec &file_spec : file_spec_list) { + m_prefixes.emplace_back(file_spec.GetPath()); + } +} + +void RealpathPrefixes::SetFileSystem( + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs) { + m_fs = fs; +} + +std::optional<FileSpec> +RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) const { + if (m_prefixes.empty()) + return std::nullopt; + + auto is_prefix = [](llvm::StringRef a, llvm::StringRef b, + bool case_sensitive) -> bool { + return case_sensitive ? a.consume_front(b) : a.consume_front_insensitive(b); ---------------- royitaqi wrote:
Ah got it. The `is_suffix` and the body of `IsCompatible()` is existing code. I refactored it from originally an inner loop into this function. It seems git wasn't able to figure out which lines are new and which is old. In general I feel prefixes on partial names generally make sense - ppl sometimes name their directories or files with the same prefix. E.g. we have `lldb/Utility/LLDBAssert.h` and `lldb/Utility/LLDBLog.h`. But not a big deal, if you think full directory/file names are better/safer, then changing into it is easy. https://github.com/llvm/llvm-project/pull/102223 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits