Date: Fri, 24 Mar 2017 14:31:57 -0700 From: Cy Schubert <Cy.Schubert@komquats.com> To: Warner Losh <imp@FreeBSD.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r315901 - head/sbin/devd Message-ID: <201703242131.v2OLVvBa047226@slippy.cwsent.com> In-Reply-To: Message from Warner Losh <imp@FreeBSD.org> of "Fri, 24 Mar 2017 13:46:26 -0000." <201703241346.v2ODkQtJ019397@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <201703241346.v2ODkQtJ019397@repo.freebsd.org>, Warner Losh writes: > Author: imp > Date: Fri Mar 24 13:46:26 2017 > New Revision: 315901 > URL: https://svnweb.freebsd.org/changeset/base/315901 > > Log: > Use a more stream-lined version of fix_value. > > Submitted by: ian@ > > Modified: > head/sbin/devd/devd.cc > head/sbin/devd/devd.hh > > Modified: head/sbin/devd/devd.cc > ============================================================================= > = > --- head/sbin/devd/devd.cc Fri Mar 24 11:46:49 2017 (r315900) > +++ head/sbin/devd/devd.cc Fri Mar 24 13:46:26 2017 (r315901) > @@ -417,24 +417,16 @@ var_list::is_set(const string &var) cons > * converted to ". For all other characters, both \ and following > * character. So the string 'fre\:\"' is translated to 'fred\:"'. > */ > -const std::string & > +std::string > var_list::fix_value(const std::string &val) const > { > - char *tmp, *dst; > - const char *src; > - std::string *rv; > - > - dst = tmp = new char[val.length()]; > - src = val.c_str(); > - while (*src) { > - if (*src == '\\' && src[1] == '"') > - src++; > - else > - *dst++ = *src++; > - } > - rv = new string(tmp); > - delete tmp; > - return *rv; > + std::string rv(val); > + std::string::size_type pos(0); > + > + while ((pos = rv.find("\\\"", pos)) != rv.npos) { > + rv.erase(pos, 1); > + } > + return (rv); > } > > void > > Modified: head/sbin/devd/devd.hh > ============================================================================= > = > --- head/sbin/devd/devd.hh Fri Mar 24 11:46:49 2017 (r315900) > +++ head/sbin/devd/devd.hh Fri Mar 24 13:46:26 2017 (r315901) > @@ -57,7 +57,7 @@ public: > static const std::string nothing; > > private: > - const std::string &fix_value(const std::string &val) const; > + std::string fix_value(const std::string &val) const; > > std::map<std::string, std::string> _vars; > }; > > Thank you Warner. -- Cheers, Cy Schubert <Cy.Schubert@cschubert.com> FreeBSD UNIX: <cy@FreeBSD.org> Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703242131.v2OLVvBa047226>