[Issue 3218] Performance of std.xml.encode must be improved
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 28 09:54:17 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3218
Andrei Alexandrescu <andrei at metalanguage.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #1 from Andrei Alexandrescu <andrei at metalanguage.com> 2009-08-28 09:54:16 PDT ---
I changed encode (which was indeed horrendous) to this:
S encode(S)(S s, S buffer = null)
{
string r;
size_t lastI;
if (buffer) buffer.length = 0;
auto result = Appender!(string)(&buffer);
foreach (i, c; s)
{
switch (c)
{
case '&': r = "&"; break;
case '"': r = """; break;
case '\'': r = "'"; break;
case '<': r = "<"; break;
case '>': r = ">"; break;
default: continue;
}
// Replace with r
result.put(s[lastI .. i]);
result.put(r);
lastI = i + 1;
}
if (!result.data) return s;
result.put(s[lastI .. $]);
return result.data;
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list