[Scummvm-cvs-logs] SF.net SVN: scummvm:[34366] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Sep 5 22:26:37 CEST 2008


Revision: 34366
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34366&view=rev
Author:   fingolfin
Date:     2008-09-05 20:26:36 +0000 (Fri, 05 Sep 2008)

Log Message:
-----------
Fix class FSDirectory (matchPattern would call getAllNames would call matchPattern would call ...); some cleanup

Modified Paths:
--------------
    scummvm/trunk/common/archive.cpp
    scummvm/trunk/common/archive.h

Modified: scummvm/trunk/common/archive.cpp
===================================================================
--- scummvm/trunk/common/archive.cpp	2008-09-05 20:08:29 UTC (rev 34365)
+++ scummvm/trunk/common/archive.cpp	2008-09-05 20:26:36 UTC (rev 34366)
@@ -159,31 +159,30 @@
 
 }
 
-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);
+	// 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::~SearchSet() {
-
-}
-
 SearchSet::ArchiveList::iterator SearchSet::find(const String &name) const {
 	ArchiveList::iterator it = _list.begin();
 	for ( ; it != _list.end(); it++) {

Modified: scummvm/trunk/common/archive.h
===================================================================
--- scummvm/trunk/common/archive.h	2008-09-05 20:08:29 UTC (rev 34365)
+++ scummvm/trunk/common/archive.h	2008-09-05 20:26:36 UTC (rev 34366)
@@ -71,9 +71,7 @@
 	 *
 	 * @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 @@
 	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 @@
 	void insert(const Node& node);
 
 public:
-	SearchSet();
-	virtual ~SearchSet();
-
 	/**
 	 * Add a new Archive to the searchable set.
 	 */
@@ -191,6 +186,9 @@
 
 	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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list