aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-09-05 20:26:36 +0000
committerMax Horn2008-09-05 20:26:36 +0000
commite5c8ebf995a8500d5c99cc238f911eac43e8073d (patch)
tree8a5d3d79555e83e7021b4debcee60d28845914a6 /common
parent2c20e138a220c706fd5d2e6c23616239566da18f (diff)
downloadscummvm-rg350-e5c8ebf995a8500d5c99cc238f911eac43e8073d.tar.gz
scummvm-rg350-e5c8ebf995a8500d5c99cc238f911eac43e8073d.tar.bz2
scummvm-rg350-e5c8ebf995a8500d5c99cc238f911eac43e8073d.zip
Fix class FSDirectory (matchPattern would call getAllNames would call matchPattern would call ...); some cleanup
svn-id: r34366
Diffstat (limited to 'common')
-rw-r--r--common/archive.cpp27
-rw-r--r--common/archive.h12
2 files changed, 18 insertions, 21 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index cac6680e76..91ed49c5c2 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -159,30 +159,29 @@ void FSDirectory::cacheDirectoryRecursive(FilesystemNode node, int depth, const
}
-int FSDirectory::matchPattern(StringList &list, const String &pattern) {
- if (pattern.empty() || !_node.isDirectory()) {
+int FSDirectory::getAllNames(StringList &list) {
+ if (!_node.isDirectory())
return 0;
- }
+ // Cache dir data
if (!_cached) {
cacheDirectoryRecursive(_node, _depth, "");
_cached = true;
}
- return Archive::matchPattern(list, pattern);
-}
-
-
-
-
-
-SearchSet::SearchSet() {
-
+ // 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++) {
+ list.push_back((*it)._key);
+ }
+
+ return _fileCache.size();
}
-SearchSet::~SearchSet() {
-}
SearchSet::ArchiveList::iterator SearchSet::find(const String &name) const {
ArchiveList::iterator it = _list.begin();
diff --git a/common/archive.h b/common/archive.h
index 1523eef651..c543e1f3c8 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -71,9 +71,7 @@ public:
*
* @return The number of names added to list.
*/
- virtual int getAllNames(StringList &list) {
- return matchPattern(list, "*");
- }
+ virtual int getAllNames(StringList &list) = 0;
/**
* Create a stream bound to a file in the archive.
@@ -139,7 +137,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);
};
@@ -166,9 +164,6 @@ class SearchSet : public Archive {
void insert(const Node& node);
public:
- SearchSet();
- virtual ~SearchSet();
-
/**
* Add a new Archive to the searchable set.
*/
@@ -191,6 +186,9 @@ public:
virtual bool hasFile(const String &name);
virtual int matchPattern(StringList &list, const String &pattern);
+ virtual int getAllNames(StringList &list) {
+ return matchPattern(list, "*");
+ }
/**
* Implements openFile from Archive base class. The current policy is