# HG changeset patch # User David Bateman # Date 1226972151 -3600 # Node ID 4a7a943581d0404a9b02d5745f7a3bd9cdf2f251 # Parent 545b9f62adcfc8abc2216b75afc3b1e585f6fc2e Fast return case for file_ops::tilde_expand diff -r 545b9f62adcf -r 4a7a943581d0 liboctave/file-ops.cc --- a/liboctave/file-ops.cc Mon Nov 17 20:04:23 2008 -0500 +++ b/liboctave/file-ops.cc Tue Nov 18 02:35:51 2008 +0100 @@ -768,53 +768,58 @@ std::string file_ops::tilde_expand (const std::string& name) { - std::string result; - - size_t name_len = name.length (); - - // Scan through S expanding tildes as we come to them. - - size_t pos = 0; - - while (1) + if (name.find ('~') == std::string::npos) + return name; + else { - if (pos > name_len) - break; + std::string result; + + size_t name_len = name.length (); - size_t len; + // Scan through S expanding tildes as we come to them. + + size_t pos = 0; - // Make START point to the tilde which starts the expansion. - - size_t start = tilde_find_prefix (name.substr (pos), len); + while (1) + { + if (pos > name_len) + break; - result.append (name.substr (pos, start)); + size_t len; + + // Make START point to the tilde which starts the expansion. - // Advance STRING to the starting tilde. + size_t start = tilde_find_prefix (name.substr (pos), len); + + result.append (name.substr (pos, start)); - pos += start; + // Advance STRING to the starting tilde. - // Make FINI be the index of one after the last character of the - // username. + pos += start; + + // Make FINI be the index of one after the last character of the + // username. - size_t fini = tilde_find_suffix (name.substr (pos)); + size_t fini = tilde_find_suffix (name.substr (pos)); - // If both START and FINI are zero, we are all done. + // If both START and FINI are zero, we are all done. - if (! (start || fini)) - break; + if (! (start || fini)) + break; - // Expand the entire tilde word, and copy it into RESULT. + // Expand the entire tilde word, and copy it into RESULT. - std::string tilde_word = name.substr (pos, fini); + std::string tilde_word = name.substr (pos, fini); - pos += fini; + pos += fini; - std::string expansion = tilde_expand_word (tilde_word); + std::string expansion = tilde_expand_word (tilde_word); - result.append (expansion); + result.append (expansion); + } + + return result; } - - return result; } // A vector version of the above.