Mailinglist Archive: yast-devel (78 mails)

< Previous Next >
[yast-devel] Re: const string &
On Fri, Oct 07, 2011 at 04:53:28PM +0200, Ladislav Slezak wrote:
Dne 7.10.2011 11:16, jsuchome@xxxxxxxxxxxxxxxxx napsal(a):

-string SnapperAgent::getValue (const YCPMap map, const string key)
+string SnapperAgent::getValue (const YCPMap map, const string key, string
if (!map->value(YCPString(key)).isNull()
&& map->value(YCPString(key))->isString())
return map->value(YCPString(key))->asString()->value();
- return "";
+ return deflt;

The "key" parameter is not changed so you could pass a reference to it
("const string &key"), that will prevent from creating unnecessary copy
of the string on function call.

"deflt" is also not changed, passing "const string &deflt" would help

Right. The same for const YCPMap& map.

(I'm not sure, I'm not C++ expert, but then you might need to create the copy
explicitly via

return string(deflt);

at the end.)

That's unnecessary, because the constructor string(const string&) is not marked
Martin Vidner, YaST developer

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
< Previous Next >