Introduce FileSystem::CalculateMD5AsString that supports any platform and make existing FileSystem::CalculateMD5 to use it.
Code from this CL will be used in http://reviews.llvm.org/D7709 to get MD5 string by a file path.
Details
Diff Detail
Event Timeline
Thanks for working on this. It always bothered me that this was platform-specific.
include/lldb/Host/FileSystem.h | ||
---|---|---|
39–41 | I think it might be more useful to put these functions in LLVM. I'm thinking we should delete both of these and add void llvm::sys::fs::md5_contents(const Twine &Path, llvm::MD5Result &Result); |
On second though, maybe this can stay here. Most applications MD5 memory buffers, not entire files, because they're the ones writing the files to begin with. I will put some comments in a followup
source/Host/common/FileSystem.cpp | ||
---|---|---|
23 | I think it would be better if this file contained a function in an anonymous namespace with a signature like this: bool CalculateMD5(StringRef path, MD5Result &result); Then, both this function and the other function could call this to get an MD5Result. From there, this whole function becomes: llvm::MD5::MD5Result result; CalculateMD5(StringRef(file_spec.GetPath()), result); high = ((uint64_t*)result)[0]; low = ((uint64_t*)result)[1]; which is much nicer than first converting a number to a string, and then converting two strings back to numbers. | |
47 | I would prefer if we used a vector<char> here. Taking up 4K of stack is a little bit obnoxious for a simple function. | |
62 | Similarly, with the aforementioned change, this function becomes: llvm::MD5::MD5Result result; CalculateMD5(StringRef(file_spec.GetPath()), result); llvm::MD5::stringifyResult(result, str); |
Move the code that calculates the MD5 into a static function that both FileSystem::CalculateMD5AsString() and FileSystem::CalculateMD5() use. See inlined comments for details.
include/lldb/Host/FileSystem.h | ||
---|---|---|
40 | I would rather not move this to LLVM just yet. We merge the top of tree SVN to many other branches internally here at apple and these internal branches link against older versions of llvm/clang that won't have this new functionality, so please leave this in FileSystem for now. | |
source/Host/common/FileSystem.cpp | ||
39–59 | Move the MD5 calculation into a static function: bool CalculateMD5 (const FileSpec &file_spec, llvm::MD5::MD5Result &md5_result); And have both versions use it. The version that wants to return two uint64 values should be able to cast the llvm::MD5::MD5Result to a "uint64_t *' and access both numbers and it then avoids creating a string and calling strtoull on the two strings. |
source/Host/common/FileSystem.cpp | ||
---|---|---|
62 | I'm not sure how important it is for you to have the result in an std::string. For example, are you going to pass it in to another API that accepts an std::string? Or are you just going to print it or log it? As a result, you might consider changing the second argument to an llvm::SmallString<32> & which will save a heap allocation and a string copy. But this is minor, so up to you. Otherwise LGTM |
source/Host/common/FileSystem.cpp | ||
---|---|---|
62 | Let me leave it as std::string since I'd prefer to keep this function signature more generic. |
AFFECTED FILES
/lldb/trunk/include/lldb/Host/FileSystem.h /lldb/trunk/lldb.xcodeproj/project.pbxproj /lldb/trunk/source/Host/CMakeLists.txt /lldb/trunk/source/Host/common/FileSystem.cpp /lldb/trunk/source/Host/posix/FileSystem.cpp /lldb/trunk/source/Host/windows/FileSystem.cpp
USERS
ovyalov (Author)
I would rather not move this to LLVM just yet. We merge the top of tree SVN to many other branches internally here at apple and these internal branches link against older versions of llvm/clang that won't have this new functionality, so please leave this in FileSystem for now.