[Scummvm-cvs-logs] SF.net SVN: scummvm:[42285] tools/branches/gsoc2009-gui

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jul 9 11:21:57 CEST 2009


Revision: 42285
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42285&view=rev
Author:   fingolfin
Date:     2009-07-09 09:21:57 +0000 (Thu, 09 Jul 2009)

Log Message:
-----------
C++ best practices suggest that you should whenever possible use const refs instead of passing objects by value (to avoid needless copies); and to pass objects as refs and not pointers (unless you want to explicitly allow NULL)

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/util.cpp
    tools/branches/gsoc2009-gui/util.h

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-07-09 09:15:43 UTC (rev 42284)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-07-09 09:21:57 UTC (rev 42285)
@@ -191,19 +191,19 @@
 	return *this;
 }
 
-void Filename::setFullPath(std::string path) {
+void Filename::setFullPath(const std::string &path) {
 	_path = path;
 }
 
-void Filename::setFullName(std::string newname) {
+void Filename::setFullName(const std::string &newname) {
 	_path = getPath() + newname;
 }
 
-void Filename::addExtension(std::string ext) {
+void Filename::addExtension(const std::string &ext) {
 	_path += ext;
 }
 
-void Filename::setExtension(std::string ext) {
+void Filename::setExtension(const std::string &ext) {
 	size_t dot = _path.rfind('.');
 	if (dot == std::string::npos) {
 		_path += ext;
@@ -213,12 +213,12 @@
 	}
 }
 
-bool Filename::equals(const Filename *other) const {
+bool Filename::equals(const Filename &other) const {
 #ifdef _WIN32
 	// On Windows paths are case-insensitive
-	return scumm_stricmp(_path.c_str(), other->_path.c_str()) == 0;
+	return scumm_stricmp(_path.c_str(), other._path.c_str()) == 0;
 #else
-	return _path == other->_path;
+	return _path == other._path;
 #endif
 }
 
@@ -258,8 +258,8 @@
 #endif
 }
 
-std::string Filename::getFullPath() const {
-	return _path.c_str();
+const std::string &Filename::getFullPath() const {
+	return _path;
 }
 
 std::string Filename::getFullName() const {

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-07-09 09:15:43 UTC (rev 42284)
+++ tools/branches/gsoc2009-gui/util.h	2009-07-09 09:21:57 UTC (rev 42285)
@@ -297,27 +297,27 @@
 	Filename(const Filename &path);
 	Filename& operator=(const Filename &fn);
 
-	void setFullPath(std::string path);
-	void setFullName(std::string name);
-	void addExtension(std::string ext);
-	void setExtension(std::string ext);
+	inline bool operator==(const Filename &fn){
+		return equals(fn);
+	}
+	
+	void setFullPath(const std::string &path);
+	void setFullName(const std::string &name);
+	void addExtension(const std::string &ext);
+	void setExtension(const std::string &ext);
 
 	bool hasExtension(std::string suffix) const;
 	bool empty() const;
-	bool equals(const Filename* other) const;
+	bool equals(const Filename &other) const;
 	
 	// Doesn't work
 	bool mkdir(int permission = 077);
 
-	std::string getFullPath() const;
+	const std::string &getFullPath() const;
 	std::string getFullName() const;
 	std::string getPath() const;
 };
 
-inline bool operator==(const Filename &f1, const Filename &f2){
-	return f1.equals(&f2);
-}
-
 /**
  * Possible modes for opening files
  */


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