# HG changeset patch # User David Bateman # Date 1227166916 -3600 # Node ID 84fb5019fb383147a97c5aaf87b2d72500b0f9e2 # Parent 53e846af744d0cc2aa6bfdde3f7ffb2a92520701 Fast return case for file_ops::tilde_expand diff -r 53e846af744d -r 84fb5019fb38 liboctave/file-ops.cc --- a/liboctave/file-ops.cc Thu Nov 20 08:41:35 2008 +0100 +++ b/liboctave/file-ops.cc Thu Nov 20 08:41:56 2008 +0100 @@ -746,53 +746,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.