Thread: [Widelands-cvs] SF.net SVN: widelands:[4084] trunk/src/io/filesystem/filesystem.cc
Status: Beta
Brought to you by:
sirver
From: <nas...@us...> - 2009-05-12 17:52:30
|
Revision: 4084 http://widelands.svn.sourceforge.net/widelands/?rev=4084&view=rev Author: nasenbaer_peter Date: 2009-05-12 17:52:20 +0000 (Tue, 12 May 2009) Log Message: ----------- Hopefully a fix for the win32 bug in network savegame loading Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2009-05-12 15:07:03 UTC (rev 4083) +++ trunk/src/io/filesystem/filesystem.cc 2009-05-12 17:52:20 UTC (rev 4084) @@ -96,8 +96,9 @@ */ std::string FileSystem::fixCrossFile(std::string path) { #ifdef WIN32 - // We simply make it absolut. - return FS_CanonicalizeName(path); + // We simply keep it as it is and do not care about slashes - they will + // be replaced with backslashes in file read actions. + return path; #else std::string fixedpath(path); std::string temp; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dw...@us...> - 2009-05-29 23:11:40
|
Revision: 4170 http://widelands.svn.sourceforge.net/widelands/?rev=4170&view=rev Author: dwarik Date: 2009-05-29 23:11:34 +0000 (Fri, 29 May 2009) Log Message: ----------- fix warning about not checking result of getcwd Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2009-05-29 20:11:29 UTC (rev 4169) +++ trunk/src/io/filesystem/filesystem.cc 2009-05-29 23:11:34 UTC (rev 4170) @@ -118,7 +118,12 @@ std::string FileSystem::getWorkingDirectory() const { #ifndef WIN32 char cwd[PATH_MAX + 1]; - getcwd(cwd, PATH_MAX); + char * result = getcwd(cwd, PATH_MAX); + if (! result) + throw File_error + ("FileSystem::getWorkingDirectory()", + "widelands", + "can't run getcwd"); return std::string(cwd); #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nas...@us...> - 2009-06-21 16:15:39
|
Revision: 4307 http://widelands.svn.sourceforge.net/widelands/?rev=4307&view=rev Author: nasenbaer_peter Date: 2009-06-21 16:15:37 +0000 (Sun, 21 Jun 2009) Log Message: ----------- fix for win32: i was declared before Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2009-06-21 13:11:07 UTC (rev 4306) +++ trunk/src/io/filesystem/filesystem.cc 2009-06-21 16:15:37 UTC (rev 4307) @@ -232,10 +232,10 @@ std::string fixedpath(path); std::string temp; uint32_t path_size = path.size(); - for (uint32_t i = 0; i < path_size; ++i) { - temp = fixedpath.at(i); + for (uint32_t j = 0; j < path_size; ++j) { + temp = fixedpath.at(j); if (temp == "/") - fixedpath.replace(i, 1, "\\"); + fixedpath.replace(j, 1, "\\"); } bool absolute = pathIsAbsolute(fixedpath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:41:05
|
Revision: 5005 http://widelands.svn.sourceforge.net/widelands/?rev=5005&view=rev Author: sirver Date: 2010-01-22 20:40:58 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Use a list instead of a vector for path elements. The FS_CanonicalizeName algorithm makes heavy use of erase(), which can cause excessive memory copying when used on a vector. A list does not have this overhead, so is ultimately more efficient. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:40:08 UTC (rev 5004) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:40:58 UTC (rev 5005) @@ -39,6 +39,7 @@ #include <cstring> #include <string> #include <vector> +#include <list> #ifdef WIN32 #include "log.h" @@ -183,10 +184,10 @@ * * \todo This does not really belong into a filesystem class */ -static std::auto_ptr< std::vector<std::string> > FS_Tokenize +static std::auto_ptr< std::list<std::string> > FS_Tokenize (std::string const & path, char filesep) { - std::auto_ptr< std::vector<std::string> > components(new std::vector<std::string>()); + std::auto_ptr< std::list<std::string> > components(new std::list<std::string>()); std::string::size_type pos; // start of token std::string::size_type pos2; // next filesep character @@ -217,8 +218,8 @@ * \todo Enable non-Unix paths */ std::string FileSystem::FS_CanonicalizeName(std::string const & path) const { - std::auto_ptr< std::vector<std::string> > components; - std::vector<std::string>::iterator i; + std::auto_ptr< std::list<std::string> > components; + std::list<std::string>::iterator i; #ifdef WIN32 // remove all slashes with backslashes so following can work. @@ -242,7 +243,7 @@ //tilde expansion if (*components->begin() == "~") { components->erase(components->begin()); - std::auto_ptr< std::vector<std::string> > homecomponents; + std::auto_ptr< std::list<std::string> > homecomponents; homecomponents = FS_Tokenize(GetHomedir(), m_filesep); components->insert (components->begin(), homecomponents->begin(), homecomponents->end()); @@ -255,7 +256,7 @@ //make relative paths absolute (so that "../../foo" can work) if (!absolute) { - std::auto_ptr< std::vector<std::string> > cwdcomponents; + std::auto_ptr< std::list<std::string> > cwdcomponents; cwdcomponents = FS_Tokenize @@ -286,10 +287,13 @@ erase = true; } - std::vector<std::string>::iterator nexti = i; + std::list<std::string>::iterator nexti = i; if (erase_prev && erase) { - components->erase(i - 1, i + 1); + std::list<std::string>::iterator j = i; + --i; + ++j; + components->erase(i, j); i = components->begin(); continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:41:54
|
Revision: 5006 http://widelands.svn.sourceforge.net/widelands/?rev=5006&view=rev Author: sirver Date: 2010-01-22 20:41:43 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Don't reset to the start of a list when erasing path nodes. The FS_CanonicalizeName algorithm would restart from the beginning if it erased path nodes that were not needed, however the erase method returns a valid iterator. Use that iterator instead of begin(). Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:40:58 UTC (rev 5005) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:41:43 UTC (rev 5006) @@ -293,13 +293,11 @@ std::list<std::string>::iterator j = i; --i; ++j; - components->erase(i, j); - i = components->begin(); + i = components->erase(i, j); continue; } if (erase) { - components->erase(i); - i = components->begin(); + i = components->erase(i); continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:42:25
|
Revision: 5007 http://widelands.svn.sourceforge.net/widelands/?rev=5007&view=rev Author: sirver Date: 2010-01-22 20:42:19 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: The nexti variable is not used, so remove it. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:41:43 UTC (rev 5006) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:42:19 UTC (rev 5007) @@ -287,8 +287,6 @@ erase = true; } - std::list<std::string>::iterator nexti = i; - if (erase_prev && erase) { std::list<std::string>::iterator j = i; --i; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:42:58
|
Revision: 5008 http://widelands.svn.sourceforge.net/widelands/?rev=5008&view=rev Author: sirver Date: 2010-01-22 20:42:52 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Add the results from FS_Tokenize directly into the node list. FS_Tokenize was returning a list of file path nodes that were being inserted into the start of the path nodes list being canonicalized. This is inefficient, as it produces copies of the nodes being tokenised. The algorithm has been changed to take an output iterator, and an inserter is being used to add the nodes directly into the components list. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:42:19 UTC (rev 5007) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:42:52 UTC (rev 5008) @@ -180,14 +180,13 @@ * Split a string into components separated by a certain character. * * \param path The path to parse - * \return a list of path components - * - * \todo This does not really belong into a filesystem class + * \param filesep The file path separator used by the native filesystem + * \param components The output iterator to place the path nodes into */ -static std::auto_ptr< std::list<std::string> > FS_Tokenize - (std::string const & path, char filesep) +template<typename Inserter> +static void FS_Tokenize + (std::string const & path, char filesep, Inserter components) { - std::auto_ptr< std::list<std::string> > components(new std::list<std::string>()); std::string::size_type pos; // start of token std::string::size_type pos2; // next filesep character @@ -201,15 +200,13 @@ //split path into it's components while (pos2 != std::string::npos) { - components->push_back(path.substr(pos, pos2 - pos)); + *components++ = path.substr(pos, pos2 - pos); pos = pos2 + 1; pos2 = path.find(filesep, pos); } //extract the last component (most probably a filename) - components->push_back(path.substr(pos)); - - return components; + *components++ = path.substr(pos); } /** @@ -218,7 +215,7 @@ * \todo Enable non-Unix paths */ std::string FileSystem::FS_CanonicalizeName(std::string const & path) const { - std::auto_ptr< std::list<std::string> > components; + std::list<std::string> components; std::list<std::string>::iterator i; #ifdef WIN32 @@ -233,42 +230,32 @@ } bool absolute = pathIsAbsolute(fixedpath); - components = FS_Tokenize(fixedpath, m_filesep); - + FS_Tokenize(fixedpath, m_filesep, + std::inserter(components, components.begin())); #else bool absolute = pathIsAbsolute(path); - components = FS_Tokenize(path, m_filesep); + FS_Tokenize(path, m_filesep, + std::inserter(components, components.begin())); #endif //tilde expansion - if (*components->begin() == "~") { - components->erase(components->begin()); - std::auto_ptr< std::list<std::string> > homecomponents; - homecomponents = FS_Tokenize(GetHomedir(), m_filesep); - components->insert - (components->begin(), homecomponents->begin(), homecomponents->end()); - + if (*components.begin() == "~") { + components.erase(components.begin()); + FS_Tokenize(GetHomedir(), m_filesep, + std::inserter(components, components.begin())); absolute = true; } - - - //make relative paths absolute (so that "../../foo" can work) if (!absolute) { - std::auto_ptr< std::list<std::string> > cwdcomponents; - - cwdcomponents = - FS_Tokenize - (m_root.empty() ? getWorkingDirectory() : m_root, m_filesep); - - components->insert - (components->begin(), cwdcomponents->begin(), cwdcomponents->end()); + FS_Tokenize + (m_root.empty() ? getWorkingDirectory() : m_root, m_filesep, + std::inserter(components, components.begin())); absolute = true; } //clean up the path - for (i = components->begin(); i != components->end();) { + for (i = components.begin(); i != components.end();) { bool erase = false; bool erase_prev = false; @@ -282,7 +269,7 @@ //remove double dot and the preceding component (if any) if (*i == "..") { - if (i != components->begin()) + if (i != components.begin()) erase_prev = true; erase = true; } @@ -291,11 +278,11 @@ std::list<std::string>::iterator j = i; --i; ++j; - i = components->erase(i, j); + i = components.erase(i, j); continue; } if (erase) { - i = components->erase(i); + i = components.erase(i); continue; } @@ -307,12 +294,12 @@ #ifndef WIN32 canonpath = absolute ? "/" : "./"; - for (i = components->begin(); i != components->end(); ++i) + for (i = components.begin(); i != components.end(); ++i) canonpath += *i + "/"; #else canonpath = absolute ? "" : ".\\"; - for (i = components->begin(); i != components->end(); ++i) + for (i = components.begin(); i != components.end(); ++i) canonpath += *i + "\\"; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:43:16
|
Revision: 5009 http://widelands.svn.sourceforge.net/widelands/?rev=5009&view=rev Author: sirver Date: 2010-01-22 20:43:09 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: On posix systems, don't generate a trailing '/'. When taking the list<string> and converting it to a path string, the previous algorithm (and what is still being done on the Windows version) built it up as 'path/' then erasing the last '/' character. Since a path will always start with either './' or '/', the algorithm can be changed to build the path up as '/path' instead, removing the need to erase the trailing '/' character. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:42:52 UTC (rev 5008) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:09 UTC (rev 5009) @@ -292,18 +292,22 @@ std::string canonpath; canonpath.reserve(path.length()); #ifndef WIN32 - canonpath = absolute ? "/" : "./"; + if (!absolute) + canonpath = "."; for (i = components.begin(); i != components.end(); ++i) - canonpath += *i + "/"; + { + canonpath.push_back('/'); + canonpath += *i; + } #else canonpath = absolute ? "" : ".\\"; for (i = components.begin(); i != components.end(); ++i) canonpath += *i + "\\"; -#endif canonpath.erase(canonpath.end() - 1); //remove trailing slash +#endif //debug info //printf("canonpath = %s\n", canonpath.c_str()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:43:33
|
Revision: 5010 http://widelands.svn.sourceforge.net/widelands/?rev=5010&view=rev Author: sirver Date: 2010-01-22 20:43:27 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Avoid unnecessary copying and checks when fixing paths on WIN32. There is no need to convert a character to a string just to check it against '/'. Also, the range-checked at(j) usage is not needed as the loop is iterating within the bounds of the string data. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:09 UTC (rev 5009) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:27 UTC (rev 5010) @@ -221,12 +221,9 @@ #ifdef WIN32 // remove all slashes with backslashes so following can work. std::string fixedpath(path); - std::string temp; - uint32_t path_size = path.size(); - for (uint32_t j = 0; j < path_size; ++j) { - temp = fixedpath.at(j); - if (temp == "/") - fixedpath.at(j) = '\\'; + for (uint32_t j = 0; j < path.size(); ++j) { + if (fixedpath[j] == '/') + fixedpath[j] = '\\'; } bool absolute = pathIsAbsolute(fixedpath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:43:54
|
Revision: 5011 http://widelands.svn.sourceforge.net/widelands/?rev=5011&view=rev Author: sirver Date: 2010-01-22 20:43:48 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Don't add empty path nodes in FS_Tokenize. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:27 UTC (rev 5010) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:48 UTC (rev 5011) @@ -200,13 +200,15 @@ //split path into it's components while (pos2 != std::string::npos) { - *components++ = path.substr(pos, pos2 - pos); + if (pos != pos2) + *components++ = path.substr(pos, pos2 - pos); pos = pos2 + 1; pos2 = path.find(filesep, pos); } //extract the last component (most probably a filename) - *components++ = path.substr(pos); + if (pos < path.length()) + *components++ = path.substr(pos); } /** @@ -236,7 +238,7 @@ #endif //tilde expansion - if (*components.begin() == "~") { + if (!components.empty() && *components.begin() == "~") { components.erase(components.begin()); FS_Tokenize(GetHomedir(), m_filesep, std::inserter(components, components.begin())); @@ -256,10 +258,6 @@ bool erase = false; bool erase_prev = false; - //remove empty components ("foo/bar//baz/") - if (i->empty()) - erase = true; - //remove single dot if (*i == ".") erase = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:44:28
|
Revision: 5012 http://widelands.svn.sourceforge.net/widelands/?rev=5012&view=rev Author: sirver Date: 2010-01-22 20:44:17 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Simplify the path cleanup algorithm. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:43:48 UTC (rev 5011) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:44:17 UTC (rev 5012) @@ -255,28 +255,17 @@ //clean up the path for (i = components.begin(); i != components.end();) { - bool erase = false; - bool erase_prev = false; - //remove single dot if (*i == ".") - erase = true; + { + i = components.erase(i); + continue; + } //remove double dot and the preceding component (if any) if (*i == "..") { if (i != components.begin()) - erase_prev = true; - erase = true; - } - - if (erase_prev && erase) { - std::list<std::string>::iterator j = i; - --i; - ++j; - i = components.erase(i, j); - continue; - } - if (erase) { + i = components.erase(--i); i = components.erase(i); continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:45:19
|
Revision: 5013 http://widelands.svn.sourceforge.net/widelands/?rev=5013&view=rev Author: sirver Date: 2010-01-22 20:45:09 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Use a temporary string for the substr value when tokenising paths. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:44:17 UTC (rev 5012) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:45:09 UTC (rev 5013) @@ -201,14 +201,18 @@ //split path into it's components while (pos2 != std::string::npos) { if (pos != pos2) - *components++ = path.substr(pos, pos2 - pos); + { + std::string node = path.substr(pos, pos2 - pos); + *components++ = node; + } pos = pos2 + 1; pos2 = path.find(filesep, pos); } //extract the last component (most probably a filename) - if (pos < path.length()) - *components++ = path.substr(pos); + std::string node = path.substr(pos); + if (!node.empty()) + *components++ = node; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:46:54
|
Revision: 5014 http://widelands.svn.sourceforge.net/widelands/?rev=5014&view=rev Author: sirver Date: 2010-01-22 20:46:30 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Factor out the FS_CanonicalizeName logic common to POSIX and WIN32 The FS_CanonicalizeName algorithm has some logic to fix the path for the WIN32 codepath. This passes that path to pathIsAbsolute and FS_Tokenize, both of which are called in the POSIX code block. To simplify the code, only the fixup code is placed within the Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:45:09 UTC (rev 5013) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:46:30 UTC (rev 5014) @@ -224,22 +224,19 @@ std::list<std::string> components; std::list<std::string>::iterator i; + std::string fixedpath(path); + #ifdef WIN32 // remove all slashes with backslashes so following can work. - std::string fixedpath(path); for (uint32_t j = 0; j < path.size(); ++j) { if (fixedpath[j] == '/') fixedpath[j] = '\\'; } +#endif bool absolute = pathIsAbsolute(fixedpath); FS_Tokenize(fixedpath, m_filesep, std::inserter(components, components.begin())); -#else - bool absolute = pathIsAbsolute(path); - FS_Tokenize(path, m_filesep, - std::inserter(components, components.begin())); -#endif //tilde expansion if (!components.empty() && *components.begin() == "~") { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:47:38
|
Revision: 5015 http://widelands.svn.sourceforge.net/widelands/?rev=5015&view=rev Author: sirver Date: 2010-01-22 20:47:27 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: The file path will always end up absolute, so simplify the code. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:46:30 UTC (rev 5014) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:47:27 UTC (rev 5015) @@ -243,15 +243,13 @@ components.erase(components.begin()); FS_Tokenize(GetHomedir(), m_filesep, std::inserter(components, components.begin())); - absolute = true; } //make relative paths absolute (so that "../../foo" can work) - if (!absolute) { + else if (!absolute) { FS_Tokenize (m_root.empty() ? getWorkingDirectory() : m_root, m_filesep, std::inserter(components, components.begin())); - absolute = true; } //clean up the path @@ -277,17 +275,12 @@ std::string canonpath; canonpath.reserve(path.length()); #ifndef WIN32 - if (!absolute) - canonpath = "."; - for (i = components.begin(); i != components.end(); ++i) { canonpath.push_back('/'); canonpath += *i; } #else - canonpath = absolute ? "" : ".\\"; - for (i = components.begin(); i != components.end(); ++i) canonpath += *i + "\\"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:48:11
|
Revision: 5016 http://widelands.svn.sourceforge.net/widelands/?rev=5016&view=rev Author: sirver Date: 2010-01-22 20:48:05 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Call pathIsAbsolute where it is used in FS_CanonicalizeName. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:47:27 UTC (rev 5015) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:48:05 UTC (rev 5016) @@ -234,7 +234,6 @@ } #endif - bool absolute = pathIsAbsolute(fixedpath); FS_Tokenize(fixedpath, m_filesep, std::inserter(components, components.begin())); @@ -246,7 +245,7 @@ } //make relative paths absolute (so that "../../foo" can work) - else if (!absolute) { + else if (!pathIsAbsolute(fixedpath)) { FS_Tokenize (m_root.empty() ? getWorkingDirectory() : m_root, m_filesep, std::inserter(components, components.begin())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <si...@us...> - 2010-01-22 20:50:09
|
Revision: 5018 http://widelands.svn.sourceforge.net/widelands/?rev=5018&view=rev Author: sirver Date: 2010-01-22 20:50:03 +0000 (Fri, 22 Jan 2010) Log Message: ----------- merge fs-optimisation: Speed up '.' and '..' checks in FS_CanonicalizeName. Modified Paths: -------------- trunk/src/io/filesystem/filesystem.cc Modified: trunk/src/io/filesystem/filesystem.cc =================================================================== --- trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:49:29 UTC (rev 5017) +++ trunk/src/io/filesystem/filesystem.cc 2010-01-22 20:50:03 UTC (rev 5018) @@ -251,19 +251,24 @@ //clean up the path for (i = components.begin(); i != components.end();) { - //remove single dot - if (*i == ".") + const char * str = (*i).c_str(); + if (*str == '.') { - i = components.erase(i); - continue; - } + ++str; - //remove double dot and the preceding component (if any) - if (*i == "..") { - if (i != components.begin()) - i = components.erase(--i); - i = components.erase(i); - continue; + //remove single dot + if (*str == '\0') + { + i = components.erase(i); + continue; + } + //remove double dot and the preceding component (if any) + else if (*str == '.' && *(str + 1) == '\0') { + if (i != components.begin()) + i = components.erase(--i); + i = components.erase(i); + continue; + } } ++i; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |