aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-09-18 08:19:00 +0000
committerMax Horn2008-09-18 08:19:00 +0000
commit722d134e7e82b20c827abdb01357949158eb9315 (patch)
treeec76197d89c9211fc266dfab0cf9a60ce1782847 /common
parent3178fad0a44d8b528019cf9914e32b701338dcdc (diff)
downloadscummvm-rg350-722d134e7e82b20c827abdb01357949158eb9315.tar.gz
scummvm-rg350-722d134e7e82b20c827abdb01357949158eb9315.tar.bz2
scummvm-rg350-722d134e7e82b20c827abdb01357949158eb9315.zip
Added 'native' implementations for FSDirectory::matchPattern & SearchSet::getAllNames (untested)
svn-id: r34599
Diffstat (limited to 'common')
-rw-r--r--common/archive.cpp38
-rw-r--r--common/archive.h5
2 files changed, 36 insertions, 7 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index 2c6e10ec01..96ecb52315 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -159,6 +159,29 @@ void FSDirectory::cacheDirectoryRecursive(FilesystemNode node, int depth, const
}
+int FSDirectory::matchPattern(StringList &list, const String &pattern) {
+ if (!_node.isDirectory())
+ return 0;
+
+ // Cache dir data
+ if (!_cached) {
+ cacheDirectoryRecursive(_node, _depth, "");
+ _cached = true;
+ }
+
+ // Small optimization: Ensure the StringList has to grow at most once
+ list.reserve(list.size() + _fileCache.size());
+
+ // Add all filenames from our cache
+ NodeCache::iterator it = _fileCache.begin();
+ for ( ; it != _fileCache.end(); it++) {
+ if (it->_key.matchString(pattern));
+ list.push_back(it->_key);
+ }
+
+ return _fileCache.size();
+}
+
int FSDirectory::getAllNames(StringList &list) {
if (!_node.isDirectory())
return 0;
@@ -266,8 +289,6 @@ bool SearchSet::hasFile(const String &name) {
}
int SearchSet::matchPattern(StringList &list, const String &pattern) {
- // Shall we short circuit out if pattern is empty?
-
int matches = 0;
ArchiveList::iterator it = _list.begin();
@@ -278,6 +299,17 @@ int SearchSet::matchPattern(StringList &list, const String &pattern) {
return matches;
}
+int SearchSet::getAllNames(StringList &list) {
+ int matches = 0;
+
+ ArchiveList::iterator it = _list.begin();
+ for ( ; it != _list.end(); it++) {
+ matches += (*it)._arc->getAllNames(list);
+ }
+
+ return matches;
+}
+
SeekableReadStream *SearchSet::openFile(const String &name) {
if (name.empty()) {
return 0;
@@ -294,8 +326,6 @@ SeekableReadStream *SearchSet::openFile(const String &name) {
}
-
-
DECLARE_SINGLETON(SearchManager);
void SearchManager::addArchive(const String &name, ArchivePtr archive) {
diff --git a/common/archive.h b/common/archive.h
index f3f121e717..89ea6a5ce2 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -138,6 +138,7 @@ public:
FSDirectory *getSubDirectory(const String &name);
virtual bool hasFile(const String &name);
+ virtual int matchPattern(StringList &list, const String &pattern);
virtual int getAllNames(StringList &list);
virtual SeekableReadStream *openFile(const String &name);
};
@@ -192,9 +193,7 @@ public:
virtual bool hasFile(const String &name);
virtual int matchPattern(StringList &list, const String &pattern);
- virtual int getAllNames(StringList &list) {
- return matchPattern(list, "*");
- }
+ virtual int getAllNames(StringList &list);
/**
* Implements openFile from Archive base class. The current policy is