diff --git a/src/CompileCommands.cc b/src/CompileCommands.cc index 8403e18..8d0d640 100644 --- a/src/CompileCommands.cc +++ b/src/CompileCommands.cc @@ -14,6 +14,7 @@ clangmm::CompileCommands::~CompileCommands() { std::vector clangmm::CompileCommands::get_commands() { unsigned size = clang_CompileCommands_getSize(cx_commands); std::vector commands; + commands.reserve(size); for (unsigned i = 0; i < size; i++) commands.emplace_back(clang_CompileCommands_getCommand(cx_commands, i)); return commands; diff --git a/src/SourceLocation.cc b/src/SourceLocation.cc index 69cae14..076e66a 100644 --- a/src/SourceLocation.cc +++ b/src/SourceLocation.cc @@ -16,13 +16,13 @@ clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string std::string clangmm::SourceLocation::get_path() { std::string path; - get_data(&path, NULL, NULL, NULL); + get_data(&path, nullptr, nullptr, nullptr); return path; } clangmm::Offset clangmm::SourceLocation::get_offset() { - unsigned line, index; - get_data(NULL, &line, &index, NULL); - return {line, index}; + unsigned line, index, offset; + get_data(nullptr, &line, &index, &offset); + return {line, index, offset}; } void clangmm::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) { diff --git a/src/SourceLocation.h b/src/SourceLocation.h index 4c3ae7c..a46e366 100644 --- a/src/SourceLocation.h +++ b/src/SourceLocation.h @@ -6,12 +6,11 @@ namespace clangmm { class Offset { public: - Offset() {} - Offset(unsigned line, unsigned index): line(line), index(index) {} - bool operator==(const clangmm::Offset &o) {return (line==o.line && index==o.index);} + bool operator==(const clangmm::Offset &o) {return offset==o.offset;} bool operator!=(const clangmm::Offset &o) {return !(*this==o);} unsigned line; unsigned index; //byte index in line (not char number) + unsigned offset; }; class SourceLocation {