[Issue 3218] Performance of std.xml.encode must be improved

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3218

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

Version|unspecified |D2

--


[Issue 3218] Performance of std.xml.encode must be improved

2009-08-28 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3218


Andrei Alexandrescu and...@metalanguage.com changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED




--- Comment #1 from Andrei Alexandrescu and...@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 = amp;; break;
case '':  r = quot;; break;
case '\'': r = apos;; break;
case '':  r = lt;; break;
case '':  r = gt;; 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: ---