From a645235d5a9bc599c7e6992d1cde7e7a668987ed Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Mon, 14 Nov 2011 09:16:47 +0100 Subject: [PATCH] Adapt Token::strAt() to return a const reference like Token::str() does Saves us a complete conversion from string.c_str() back to std::string. --- lib/token.cpp | 6 ++++-- lib/token.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index bdca266e4..42097422e 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -233,10 +233,12 @@ Token *Token::linkAt(int index) return tok->link(); } -std::string Token::strAt(int index) const +const std::string &Token::strAt(int index) const { + static const std::string empty_str; + const Token *tok = this->tokAt(index); - return tok ? tok->_str.c_str() : ""; + return tok ? tok->_str : empty_str; } static bool strisop(const char str[]) diff --git a/lib/token.h b/lib/token.h index 03032cd47..bb5614910 100644 --- a/lib/token.h +++ b/lib/token.h @@ -78,7 +78,7 @@ public: const Token *linkAt(int index) const; Token *linkAt(int index); - std::string strAt(int index) const; + const std::string &strAt(int index) const; /** * Match given token (or list of tokens) to a pattern list.