logic: reduce access to filesystem while indexing

* use canonical filepath cache in cxx indexer
* made constructors of FilePath explicit
* use FilePath at more places instead of string
* forward declares FilePath wherever possible
This commit is contained in:
malte_langkabel
2017-05-04 10:55:16 +02:00
parent 55d3f9c189
commit 054b8fab17
156 changed files with 656 additions and 444 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ public:
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad(getConfigTextAccess());
config->save("data/temp.xml");
std::shared_ptr<ConfigManager> config2 = ConfigManager::createAndLoad(TextAccess::createFromFile("data/temp.xml"));
std::shared_ptr<ConfigManager> config2 = ConfigManager::createAndLoad(TextAccess::createFromFile(FilePath("data/temp.xml")));
TS_ASSERT_EQUALS(config->toString(), config2->toString());
}
+1 -1
View File
@@ -3319,7 +3319,7 @@ public:
void test_cxx_parser_parses_multiple_files()
{
std::set<FilePath> indexedPaths;
indexedPaths.insert("data/CxxParserTestSuite/");
indexedPaths.insert(FilePath("data/CxxParserTestSuite/"));
std::shared_ptr<IndexerCommandCxxManual> indexerCommand = std::make_shared<IndexerCommandCxxManual>(
FilePath("data/CxxParserTestSuite/code.cpp"),
+2 -2
View File
@@ -8,8 +8,8 @@ public:
void test_file_manager_has_added_file_paths_after_first_fetch()
{
std::vector<FilePath> sourcePaths;
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
sourcePaths.push_back("./data/FileManagerTestSuite/include/");
sourcePaths.push_back(FilePath("./data/FileManagerTestSuite/src/"));
sourcePaths.push_back(FilePath("./data/FileManagerTestSuite/include/"));
std::vector<FilePath> headerPaths;
std::vector<FilePath> excludePaths;
std::vector<std::string> sourceExtensions;
+1 -1
View File
@@ -124,7 +124,7 @@ public:
{
FilePath path("data/FilePathTestSuite/a.h");
TS_ASSERT_EQUALS(path.withoutExtension(), "data/FilePathTestSuite/a");
TS_ASSERT_EQUALS(path.withoutExtension(), FilePath("data/FilePathTestSuite/a"));
}
void test_file_path_has_extension()
+7 -7
View File
@@ -16,7 +16,7 @@ public:
extensions.push_back(".cpp");
std::vector<std::string> cppFiles =
FileSystem::getFileNamesFromDirectory("data/FileSystemTestSuite", extensions);
FileSystem::getFileNamesFromDirectory(FilePath("data/FileSystemTestSuite"), extensions);
TS_ASSERT_EQUALS(cppFiles.size(), 4);
TS_ASSERT(isInVector(cppFiles, "data/FileSystemTestSuite/main.cpp"));
@@ -31,7 +31,7 @@ public:
extensions.push_back(".h");
std::vector<std::string> headerFiles =
FileSystem::getFileNamesFromDirectory("data/FileSystemTestSuite", extensions);
FileSystem::getFileNamesFromDirectory(FilePath("data/FileSystemTestSuite"), extensions);
TS_ASSERT_EQUALS(headerFiles.size(), 3);
TS_ASSERT(isInVector(headerFiles, "data/FileSystemTestSuite/tictactoe.h"));
@@ -47,7 +47,7 @@ public:
extensions.push_back(".cpp");
std::vector<std::string> sourceFiles =
FileSystem::getFileNamesFromDirectory("data/FileSystemTestSuite", extensions);
FileSystem::getFileNamesFromDirectory(FilePath("data/FileSystemTestSuite"), extensions);
TS_ASSERT_EQUALS(sourceFiles.size(), 8);
}
@@ -105,14 +105,14 @@ public:
void test_filesystem_finds_existing_files()
{
TS_ASSERT(FileSystem::exists("data/FileSystemTestSuite"));
TS_ASSERT(FileSystem::exists("data/FileSystemTestSuite/tictactoe.h"));
TS_ASSERT(FileSystem::exists(FilePath("data/FileSystemTestSuite")));
TS_ASSERT(FileSystem::exists(FilePath("data/FileSystemTestSuite/tictactoe.h")));
}
void test_filesystem_does_not_find_non_existing_files()
{
TS_ASSERT(!FileSystem::exists("data/FileSystemTestSuite/foo"));
TS_ASSERT(!FileSystem::exists("data/FileSystemTestSuite/blabla.h"));
TS_ASSERT(!FileSystem::exists(FilePath("data/FileSystemTestSuite/foo")));
TS_ASSERT(!FileSystem::exists(FilePath("data/FileSystemTestSuite/blabla.h")));
}
void test_filesystem_extracts_filename()
+1 -1
View File
@@ -842,7 +842,7 @@ private:
setupJavaEnvironmentFactory();
JavaParser parser(parserClient, nullptr);
parser.buildIndex("input.cc", textAccess);
parser.buildIndex(FilePath("input.cc"), textAccess);
return parserClient;
}
+7 -7
View File
@@ -10,19 +10,19 @@ public:
void test_settings_get_loaded_from_file()
{
TestSettings settings;
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
TS_ASSERT(settings.load(FilePath("data/SettingsTestSuite/settings.xml")));
}
void test_settings_get_not_loaded_from_file()
{
TestSettings settings;
TS_ASSERT(!settings.load("data/SettingsTestSuite/wrong_settings.xml"));
TS_ASSERT(!settings.load(FilePath("data/SettingsTestSuite/wrong_settings.xml")));
}
void test_settings_get_loaded_value()
{
TestSettings settings;
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
TS_ASSERT(settings.load(FilePath("data/SettingsTestSuite/settings.xml")));
TS_ASSERT_EQUALS(settings.getBool(), true);
TS_ASSERT_EQUALS(settings.getInt(), 42);
@@ -42,7 +42,7 @@ public:
void test_settings_get_default_value_when_wrongly_loaded()
{
TestSettings settings;
TS_ASSERT(!settings.load("data/SettingsTestSuite/wrong_settings.xml"));
TS_ASSERT(!settings.load(FilePath("data/SettingsTestSuite/wrong_settings.xml")));
TS_ASSERT_EQUALS(settings.getBool(), false);
TS_ASSERT_EQUALS(settings.getInt(), -1);
@@ -53,7 +53,7 @@ public:
void test_settings_get_default_value_after_clearing()
{
TestSettings settings;
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
TS_ASSERT(settings.load(FilePath("data/SettingsTestSuite/settings.xml")));
settings.clear();
TS_ASSERT_EQUALS(settings.getBool(), false);
@@ -82,7 +82,7 @@ public:
void test_settings_can_be_replaced_when_loaded()
{
TestSettings settings;
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
TS_ASSERT(settings.load(FilePath("data/SettingsTestSuite/settings.xml")));
TS_ASSERT(settings.setBool(false));
TS_ASSERT_EQUALS(settings.getBool(), false);
@@ -100,7 +100,7 @@ public:
void test_settings_can_be_added_when_loaded()
{
TestSettings settings;
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
TS_ASSERT(settings.load(FilePath("data/SettingsTestSuite/settings.xml")));
TS_ASSERT_EQUALS(settings.getNewBool(), false);
TS_ASSERT(settings.setNewBool(true));
+20 -20
View File
@@ -10,7 +10,7 @@ public:
void test_source_locations_get_created_with_other_end()
{
SourceLocationCollection collection;
const SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
const SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 2, 3, 4, 5);
TS_ASSERT(a);
TS_ASSERT(a->isStartLocation());
@@ -32,8 +32,8 @@ public:
void test_source_locations_do_not_get_created_with_wrong_input()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 2, 1);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 4, 1, 1, 10);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 2, 3, 2, 1);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, FilePath("file.c"), 4, 1, 1, 10);
TS_ASSERT(!a);
TS_ASSERT(!b);
@@ -42,9 +42,9 @@ public:
void test_source_locations_get_unique_id_but_both_ends_have_the_same()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 1, 1, 1, 1);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {2}, "file.c", 1, 1, 1, 1);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {3}, "file.c", 1, 1, 1, 1);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 1, 1, 1, 1);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {2}, FilePath("file.c"), 1, 1, 1, 1);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {3}, FilePath("file.c"), 1, 1, 1, 1);
TS_ASSERT_EQUALS(1, collection.getSourceLocationFileCount());
TS_ASSERT_EQUALS(3, collection.getSourceLocationCount());
@@ -65,7 +65,7 @@ public:
void test_source_locations_have_right_file_path_line_column_and_token_id()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 2, 3, 4, 5);
TS_ASSERT_EQUALS(1, a->getTokenIds()[0]);
TS_ASSERT_EQUALS(2, a->getLineNumber());
@@ -78,8 +78,8 @@ public:
void test_finding_source_locations_by_id()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {6}, "file.c", 7, 8, 9, 10);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 2, 3, 4, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {6}, FilePath("file.c"), 7, 8, 9, 10);
TS_ASSERT_EQUALS(a, collection.getSourceLocationById(a->getLocationId()));
TS_ASSERT_EQUALS(b, collection.getSourceLocationById(b->getLocationId()));
@@ -88,10 +88,10 @@ public:
void test_creating_plain_copy_of_all_locations_in_line_range()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 3, 3, 4, 5);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, "file.c", 1, 3, 5, 5);
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, "file.c", 1, 5, 4, 5);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 2, 3, 4, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, FilePath("file.c"), 3, 3, 4, 5);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, FilePath("file.c"), 1, 3, 5, 5);
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, FilePath("file.c"), 1, 5, 4, 5);
Id ida = a->getLocationId();
Id idb = b->getLocationId();
@@ -135,13 +135,13 @@ public:
void test_get_source_locations_filtered_by_lines()
{
SourceLocationCollection collection;
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 1, 3, 1, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 1, 3, 2, 5);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, "file.c", 2, 3, 2, 5);
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, "file.c", 3, 3, 4, 5);
SourceLocation* e = collection.addSourceLocation(LOCATION_TOKEN, 5, {1}, "file.c", 3, 5, 5, 5);
SourceLocation* f = collection.addSourceLocation(LOCATION_TOKEN, 6, {1}, "file.c", 1, 5, 5, 5);
SourceLocation* g = collection.addSourceLocation(LOCATION_TOKEN, 7, {1}, "file.c", 5, 5, 5, 5);
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, FilePath("file.c"), 1, 3, 1, 5);
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, FilePath("file.c"), 1, 3, 2, 5);
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, FilePath("file.c"), 2, 3, 2, 5);
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, FilePath("file.c"), 3, 3, 4, 5);
SourceLocation* e = collection.addSourceLocation(LOCATION_TOKEN, 5, {1}, FilePath("file.c"), 3, 5, 5, 5);
SourceLocation* f = collection.addSourceLocation(LOCATION_TOKEN, 6, {1}, FilePath("file.c"), 1, 5, 5, 5);
SourceLocation* g = collection.addSourceLocation(LOCATION_TOKEN, 7, {1}, FilePath("file.c"), 5, 5, 5, 5);
SourceLocationCollection copy;
copy.addSourceLocationFile(
+13 -11
View File
@@ -11,11 +11,11 @@ class SqliteBookmarkStorageTestSuite: public CxxTest::TestSuite
public:
void test_add_bookmarks()
{
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
FilePath databasePath("data/SQLiteTestSuite/bookmarkTest.sqlite");
int bookmarkCount = 4;
int result = -1;
{
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
SqliteBookmarkStorage storage(databasePath);
storage.setup();
@@ -28,18 +28,18 @@ public:
result = storage.getAllBookmarks().size();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(result, bookmarkCount);
}
void test_add_bookmarked_node()
{
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
FilePath databasePath("data/SQLiteTestSuite/bookmarkTest.sqlite");
int bookmarkCount = 4;
int result = -1;
{
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
SqliteBookmarkStorage storage(databasePath);
storage.setup();
@@ -54,18 +54,18 @@ public:
result = storage.getAllBookmarkedNodes().size();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(result, bookmarkCount);
}
void test_remove_bookmark_also_removes_bookmarked_node()
{
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
FilePath databasePath("data/SQLiteTestSuite/bookmarkTest.sqlite");
int bookmarkCount = 4;
int result = -1;
{
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
SqliteBookmarkStorage storage(databasePath);
storage.setup();
@@ -78,21 +78,21 @@ public:
result = storage.getAllBookmarkedNodes().size();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(result, 0);
}
void test_edit_nodeBookmark()
{
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
FilePath databasePath("data/SQLiteTestSuite/bookmarkTest.sqlite");
const std::string updatedName = "updated name";
const std::string updatedComment = "updated comment";
StorageBookmark storageBookmark;
{
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
SqliteBookmarkStorage storage(databasePath);
storage.setup();
@@ -105,6 +105,8 @@ public:
storageBookmark = storage.getAllBookmarks().front();
}
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(updatedName, storageBookmark.name);
TS_ASSERT_EQUALS(updatedComment, storageBookmark.comment);
}
+8 -8
View File
@@ -10,7 +10,7 @@ class SqliteIndexStorageTestSuite: public CxxTest::TestSuite
public:
void test_storage_adds_node_successfully()
{
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
FilePath databasePath("data/SQLiteTestSuite/test.sqlite");
int nodeCount = -1;
{
SqliteIndexStorage storage(databasePath);
@@ -20,14 +20,14 @@ public:
storage.commitTransaction();
nodeCount = storage.getNodeCount();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(1, nodeCount);
}
void test_storage_removes_node_successfully()
{
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
FilePath databasePath("data/SQLiteTestSuite/test.sqlite");
int nodeCount = -1;
{
SqliteIndexStorage storage(databasePath);
@@ -38,14 +38,14 @@ public:
storage.commitTransaction();
nodeCount = storage.getNodeCount();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(0, nodeCount);
}
void test_storage_adds_edge_successfully()
{
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
FilePath databasePath("data/SQLiteTestSuite/test.sqlite");
int edgeCount = -1;
{
SqliteIndexStorage storage(databasePath);
@@ -57,14 +57,14 @@ public:
storage.commitTransaction();
edgeCount = storage.getEdgeCount();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(1, edgeCount);
}
void test_storage_removes_edge_successfully()
{
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
FilePath databasePath("data/SQLiteTestSuite/test.sqlite");
int edgeCount = -1;
{
SqliteIndexStorage storage(databasePath);
@@ -77,7 +77,7 @@ public:
storage.commitTransaction();
edgeCount = storage.getEdgeCount();
}
boost::filesystem::remove(databasePath);
boost::filesystem::remove(databasePath.path());
TS_ASSERT_EQUALS(0, edgeCount);
}
+3 -3
View File
@@ -13,7 +13,7 @@ class StorageTestSuite: public CxxTest::TestSuite
public:
void setUp()
{
m_filePath = "file.cpp";
m_filePath = FilePath("file.cpp");
}
void test_storage_saves_file()
@@ -232,7 +232,7 @@ private:
{
public:
TestStorage()
: PersistentStorage("data/test.sqlite", "data/testBookmarks.sqlite")
: PersistentStorage(FilePath("data/test.sqlite"), FilePath("data/testBookmarks.sqlite"))
{
clear();
}
@@ -279,5 +279,5 @@ private:
return nameHierarchy;
}
std::string m_filePath;
FilePath m_filePath;
};
+4 -4
View File
@@ -87,7 +87,7 @@ public:
void test_textAccessFile_constructor()
{
std::string filePath = "data/TextAccessTestSuite/text.txt";
FilePath filePath("data/TextAccessTestSuite/text.txt");
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
@@ -96,7 +96,7 @@ public:
void test_textAccessFile_lines_count()
{
std::string filePath = "data/TextAccessTestSuite/text.txt";
FilePath filePath("data/TextAccessTestSuite/text.txt");
unsigned int lineCount = 7;
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
@@ -106,7 +106,7 @@ public:
void test_textAccessFile_lines_content()
{
std::string filePath = "data/TextAccessTestSuite/text.txt";
FilePath filePath("data/TextAccessTestSuite/text.txt");
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
std::vector<std::string> lines = textAccess->getLines(1, 4);
@@ -120,7 +120,7 @@ public:
void test_textAccessFile_get_filePath()
{
std::string filePath = "data/TextAccessTestSuite/text.txt";
FilePath filePath("data/TextAccessTestSuite/text.txt");
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
TS_ASSERT_EQUALS(textAccess->getFilePath(), filePath);