Fixed a major bug. Improved speed further.

This commit is contained in:
YotaXP
2014-01-08 23:03:43 -05:00
committed by Mloc
parent 794be2b31e
commit c6d820b04f

View File

@@ -85,44 +85,49 @@
// Concatenates a list of strings into a single string. A seperator may optionally be provided. // Concatenates a list of strings into a single string. A seperator may optionally be provided.
/proc/list2text(list/ls, sep) /proc/list2text(list/ls, sep)
if(ls.len <= 1) return ls.len ? ls[1] : "" if(ls.len <= 1) // Early-out code for empty or singleton lists.
. = "" return ls.len ? ls[1] : ""
var/l = ls.len
var/i = 0
if(sep) var/l = ls.len // Made local for sanic speed.
#define S1 ls[++i] var/i = 0 // Incremented every time a list index is accessed.
#define S4 S1, sep, S1, sep, S1, sep, S1
#define S16 S4, sep, S4, sep, S4, sep, S4
#define S64 S16, sep, S16, sep, S16, sep, S16
while(l-i >= 128) if(sep <> null)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ // Macros expand to long argument lists like so: sep, ls[++i], sep, ls[++i], sep, ls[++i], etc...
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ #define S1 sep, ls[++i]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ #define S4 S1, S1, S1, S1
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ #define S16 S4, S4, S4, S4
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ #define S64 S16, S16, S16, S16
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ . = "[ls[++i]]" // Make sure the initial element is converted to text.
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, sep, S64)
if(l-i >= 64) // Having the small concatenations come before the large ones boosted speed by an average of at least 5%.
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ if(l-1 & 0x01) // 'i' will always be 1 here.
. = text("[][][]", ., S1) // Append 1 element if the remaining elements are not a multiple of 2.
if(l-i & 0x02)
. = text("[][][][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
if(l-i & 0x04)
. = text("[][][][][][][][][]", ., S4) // And so on....
if(l-i & 0x08)
. = text("[][][][][][][][][][][][][][][][][]", ., S4, S4)
if(l-i & 0x10)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
if(l-i & 0x20)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
if(l-i & 0x40)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
if(l-i >= 32) while(l > i) // Chomp through the rest of the list, 128 elements at a time.
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, sep, S16) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
if(l-i >= 16) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
if(l-i >= 8) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
. = text("[][][][][][][][][][][][][][][][]", ., S4, sep, S4) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
if(l-i >= 4) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
. = text("[][][][][][][][]", ., S4) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
if(l-i >= 2)
. = text("[][][][]", ., S1, sep, S1)
if(l > i)
. = text("[][][]", ., sep, S1)
#undef S64 #undef S64
#undef S16 #undef S16
@@ -130,31 +135,34 @@
#undef S1 #undef S1
else else
// Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
#define S1 ls[++i] #define S1 ls[++i]
#define S4 S1, S1, S1, S1 #define S4 S1, S1, S1, S1
#define S16 S4, S4, S4, S4 #define S16 S4, S4, S4, S4
#define S64 S16, S16, S16, S16 #define S64 S16, S16, S16, S16
while(l-i >= 128) . = "[ls[++i]]" // Make sure the initial element is converted to text.
if(l-1 & 0x01) // 'i' will always be 1 here.
. += S1 // Append 1 element if the remaining elements are not a multiple of 2.
if(l-i & 0x02)
. = text("[][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
if(l-i & 0x04)
. = text("[][][][][]", ., S4) // And so on...
if(l-i & 0x08)
. = text("[][][][][][][][][]", ., S4, S4)
if(l-i & 0x10)
. = text("[][][][][][][][][][][][][][][][][]", ., S16)
if(l-i & 0x20)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
if(l-i & 0x40)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64) [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
if(l-i >= 64)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
if(l-i >= 32)
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
if(l-i >= 16)
. = text("[][][][][][][][][][][][][][][][][]", ., S16)
if(l-i >= 8)
. = text("[][][][][][][][][]", ., S4, S4)
if(l-i >= 4)
. = text("[][][][][]", ., S4)
if(l-i >= 2)
. = text("[][][]", ., S1, S1)
if(l > i)
. += S1
#undef S64 #undef S64
#undef S16 #undef S16