[Issue 3218] New: Performance of std.xml.encode must be improved
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 30 20:00:39 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3218
Summary: Performance of std.xml.encode must be improved
Product: D
Version: unspecified
Platform: Other
OS/Version: Linux
Status: ASSIGNED
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: andrei at metalanguage.com
ReportedBy: andrei at metalanguage.com
I'm relaying this on behalf of zsxxsz <zhengshuxin at hexun.com>, see
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=94478:
=============================
Hi, below are the functions from Phobos and Tango with the same use, we can
see why so many people like Tango more than Phobos.
>>> In Phobos:
string encode(string s)
{
// The ifs are (temprarily, we hope) necessary, because
// std.string.write.replace
// does not do copy-on-write, but instead copies always.
if (s.indexOf('&') != -1) s = replace(s,"&","&");
if (s.indexOf('"') != -1) s = replace(s,"\"",""");
if (s.indexOf("'") != -1) s = replace(s,"'","'");
if (s.indexOf('<') != -1) s = replace(s,"<","<");
if (s.indexOf('>') != -1) s = replace(s,">",">");
return s;
}
>>>In Tango:
T[] toEntity(T) (T[] src, T[] dst = null)
{
T[] entity;
auto s = src.ptr;
auto t = s;
auto e = s + src.length;
auto index = 0;
while (s < e)
switch (*s)
{
case '"':
entity = """;
goto common;
case '>':
entity = ">";
goto common;
case '<':
entity = "<";
goto common;
case '&':
entity = "&";
goto common;
case '\'':
entity = "'";
goto common;
common:
auto len = s - t;
if (dst.length <= index + len + entity.length)
dst.length = (dst.length + len + entity.length)
+ dst.length / 2;
dst [index .. index + len] = t [0 .. len];
index += len;
dst [index .. index + entity.length] = entity;
index += entity.length;
t = ++s;
break;
default:
++s;
break;
}
// did we change anything?
if (index)
{
// copy tail too
auto len = e - t;
if (dst.length <= index + len)
dst.length = index + len;
dst [index .. index + len] = t [0 .. len];
return dst [0 .. index + len];
}
return src;
}
We can see the function's performance from Tango is more high than which one
from Phobos. This maybe not the only one function difference. :)
--
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