From f98a57b7504547a4b0a75c8c576b2ca30973daec Mon Sep 17 00:00:00 2001
From: YotaXP
Date: Tue, 7 Jan 2014 22:15:25 -0500
Subject: [PATCH 1/3] Optimized and refactored list2text, text2list, and
replacetext.
Also fixed some grammar in the station blueprint code.
---
code/__HELPERS/text.dm | 47 +-----
code/__HELPERS/type2type.dm | 159 +++++++++++-------
code/datums/diseases/advance/advance.dm | 2 +-
code/game/objects/items/blueprints.dm | 24 +--
code/game/objects/items/devices/uplinks.dm | 2 +-
code/game/objects/structures/transit_tubes.dm | 2 +-
code/modules/admin/create_mob.dm | 2 +-
code/modules/admin/create_object.dm | 4 +-
code/modules/admin/create_turf.dm | 2 +-
code/modules/admin/topic.dm | 2 +-
code/modules/admin/verbs/debug.dm | 14 +-
code/modules/clothing/masks/gasmask.dm | 2 +-
code/modules/detectivework/scanner.dm | 2 +-
code/modules/flufftext/TextFilters.dm | 4 +-
code/modules/mob/living/carbon/human/say.dm | 2 +-
code/modules/mob/living/silicon/ai/say.dm | 2 +-
code/world.dm | 2 +-
17 files changed, 135 insertions(+), 139 deletions(-)
diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm
index 7b7ba3f78ba..c050d2cdc6a 100644
--- a/code/__HELPERS/text.dm
+++ b/code/__HELPERS/text.dm
@@ -178,32 +178,10 @@
* Text modification
*/
/proc/replacetext(text, find, replacement)
- var/find_len = length(find)
- if(find_len < 1) return text
- . = ""
- var/last_found = 1
- while(1)
- var/found = findtext(text, find, last_found, 0)
- . += copytext(text, last_found, found)
- if(found)
- . += replacement
- last_found = found + find_len
- continue
- return .
+ return list2text(text2list(text, find), replacement)
/proc/replacetextEx(text, find, replacement)
- var/find_len = length(find)
- if(find_len < 1) return text
- . = ""
- var/last_found = 1
- while(1)
- var/found = findtextEx(text, find, last_found, 0)
- . += copytext(text, last_found, found)
- if(found)
- . += replacement
- last_found = found + find_len
- continue
- return .
+ return list2text(text2listEx(text, find), replacement)
//Adds 'u' number of zeros ahead of the text 't'
/proc/add_zero(t, u)
@@ -270,27 +248,6 @@
return message
return copytext(message, 1, length + 1)
-/*
- * Misc
- */
-
-/proc/stringsplit(txt, character)
- var/cur_text = txt
- var/last_found = 1
- var/found_char = findtext(cur_text,character)
- var/list/list = list()
- if(found_char)
- var/fs = copytext(cur_text,last_found,found_char)
- list += fs
- last_found = found_char+length(character)
- found_char = findtext(cur_text,character,last_found)
- while(found_char)
- var/found_string = copytext(cur_text,last_found,found_char)
- last_found = found_char+length(character)
- list += found_string
- found_char = findtext(cur_text,character,last_found)
- list += copytext(cur_text,last_found,length(cur_text)+1)
- return list
/proc/stringmerge(var/text,var/compare,replace = "*")
//This proc fills in all spaces with the "replace" var (* by default) with whatever
diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm
index b62d1947db6..48ee97fc180 100644
--- a/code/__HELPERS/type2type.dm
+++ b/code/__HELPERS/type2type.dm
@@ -61,22 +61,86 @@
return .
-//Attaches each element of a list to a single string seperated by 'seperator'.
-/proc/dd_list2text(var/list/the_list, separator)
- var/total = the_list.len
- if(!total)
- return
- var/count = 2
- var/newText = "[the_list[1]]"
- while(count <= total)
- if(separator)
- newText += separator
- newText += "[the_list[count]]"
- count++
- return newText
+// Concatenates a list of strings into a single string. A seperator may optionally be provided.
+/proc/list2text(list/ls, sep)
+ if(ls.len <= 1) return ls.len ? ls[1] : ""
+ . = ""
+ var/l = ls.len
+ var/i = 0
+
+ if(sep)
+ #define S1 ls[++i]
+ #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)
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, sep, S64)
+ if(l-i >= 64)
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
+ if(l-i >= 32)
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, sep, S16)
+ if(l-i >= 16)
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
+ if(l-i >= 8)
+ . = text("[][][][][][][][][][][][][][][][]", ., S4, sep, S4)
+ if(l-i >= 4)
+ . = text("[][][][][][][][]", ., S4)
+ if(l-i >= 2)
+ . = text("[][][][]", ., S1, sep, S1)
+ if(l > i)
+ . = text("[][][]", ., sep, S1)
+
+ #undef S64
+ #undef S16
+ #undef S4
+ #undef S1
+
+ else
+ #define S1 ls[++i]
+ #define S4 S1, S1, S1, S1
+ #define S16 S4, S4, S4, S4
+ #define S64 S16, S16, S16, S16
+
+ while(l-i >= 128)
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., 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 S16
+ #undef S4
+ #undef S1
-//slower then dd_list2text, but correctly processes associative lists.
+//slower then list2text, but correctly processes associative lists.
proc/tg_list2text(list/list, glue=",")
if(!istype(list) || !list.len)
return
@@ -86,56 +150,31 @@ proc/tg_list2text(list/list, glue=",")
return output
-//Converts a text string into a list by splitting the string at each seperator found in text (discarding the seperator)
-//Returns an empty list if the text cannot be split, or the split text in a list.
-//Not giving a "" seperator will cause the text to be broken into a list of single letters.
-/proc/text2list(text, seperator="\n")
+//Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator)
+/proc/text2list(text, delimiter="\n")
+ var/delim_len = length(delimiter)
+ if(delim_len < 1) return list(text)
. = list()
+ var/last_found = 1
+ var/found
+ do
+ found = findtext(text, delimiter, last_found, 0)
+ . += copytext(text, last_found, found)
+ last_found = found + delim_len
+ while(found)
- var/text_len = length(text) //length of the input text
- var/seperator_len = length(seperator) //length of the seperator text
-
- if(text_len >= seperator_len)
- var/i
- var/last_i = 1
-
- for(i=1,i<=(text_len+1-seperator_len),i++)
- if( cmptext(copytext(text,i,i+seperator_len), seperator) )
- if(i != last_i)
- . += copytext(text,last_i,i)
- last_i = i + seperator_len
-
- if(last_i <= text_len)
- . += copytext(text, last_i, 0)
- else
- . += text
- return .
-
-//Converts a text string into a list by splitting the string at each seperator found in text (discarding the seperator)
-//Returns an empty list if the text cannot be split, or the split text in a list.
-//Not giving a "" seperator will cause the text to be broken into a list of single letters.
//Case Sensitive!
-/proc/text2listEx(text, seperator="\n")
+/proc/text2listEx(text, delimiter="\n")
+ var/delim_len = length(delimiter)
+ if(delim_len < 1) return list(text)
. = list()
-
- var/text_len = length(text) //length of the input text
- var/seperator_len = length(seperator) //length of the seperator text
-
- if(text_len >= seperator_len)
- var/i
- var/last_i = 1
-
- for(i=1,i<=(text_len+1-seperator_len),i++)
- if( cmptextEx(copytext(text,i,i+seperator_len), seperator) )
- if(i != last_i)
- . += copytext(text,last_i,i)
- last_i = i + seperator_len
-
- if(last_i <= text_len)
- . += copytext(text, last_i, 0)
- else
- . += text
- return .
+ var/last_found = 1
+ var/found
+ do
+ found = findtextEx(text, delimiter, last_found, 0)
+ . += copytext(text, last_found, found)
+ last_found = found + delim_len
+ while(found)
//Splits the text of a file at seperator and returns them in a list.
/proc/file2list(filename, seperator="\n")
diff --git a/code/datums/diseases/advance/advance.dm b/code/datums/diseases/advance/advance.dm
index ee8f7c2ae55..0b3e1e7e17b 100644
--- a/code/datums/diseases/advance/advance.dm
+++ b/code/datums/diseases/advance/advance.dm
@@ -292,7 +292,7 @@ var/list/advance_cures = list(
for(var/datum/symptom/S in symptoms)
L += S.id
L = sortList(L) // Sort the list so it doesn't matter which order the symptoms are in.
- var/result = dd_list2text(L, ":")
+ var/result = list2text(L, ":")
id = result
return result
diff --git a/code/game/objects/items/blueprints.dm b/code/game/objects/items/blueprints.dm
index 792b13ae9e6..85898b029fb 100644
--- a/code/game/objects/items/blueprints.dm
+++ b/code/game/objects/items/blueprints.dm
@@ -1,6 +1,6 @@
/obj/item/blueprints
- name = "\proper the station blueprints"
- desc = "Blueprints of the station. There's stamp \"Classified\" and several coffee stains on it."
+ name = "station blueprints"
+ desc = "Blueprints of the station. There is a \"Classified\" stamp and several coffee stains on it."
icon = 'icons/obj/items.dmi'
icon_state = "blueprints"
attack_verb = list("attacked", "bapped", "hit")
@@ -21,7 +21,7 @@
/obj/item/blueprints/attack_self(mob/M as mob)
if (!istype(M,/mob/living/carbon/human))
- M << "This is stack of useless pieces of harsh paper." //monkeys cannot into projecting
+ M << "This stack of blue paper means nothing to you." //monkeys cannot into projecting
return
interact()
return
@@ -53,18 +53,18 @@
switch (get_area_type())
if (AREA_SPACE)
text += {"
-According this blueprints you are in open space now.
+According the blueprints, you are now in outer space. Hold your breath.
Mark this place as new area.
"}
if (AREA_STATION)
text += {"
-According this blueprints you are in [A.name] now.
+According the blueprints, you are now in \"[A.name]\".
You may
move an amendment to the drawing.
"}
if (AREA_SPECIAL)
text += {"
-This place isn't noted on these blueprints.
+This place isn't noted on the blueprint.
"}
else
return
@@ -105,20 +105,20 @@ move an amendment to the drawing.
if(!istype(res,/list))
switch(res)
if(ROOM_ERR_SPACE)
- usr << "\red New area must be complete airtight!"
+ usr << "\red The new area must be completely airtight!"
return
if(ROOM_ERR_TOOLARGE)
- usr << "\red New area too large!"
+ usr << "\red The new area too large!"
return
else
usr << "\red Error! Please notify administration!"
return
var/list/turf/turfs = res
- var/str = trim(stripped_input(usr,"New area title","Blueprints editing", "", MAX_NAME_LEN))
+ var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", "", MAX_NAME_LEN))
if(!str || !length(str)) //cancel
return
if(length(str) > 50)
- usr << "\red Text too long."
+ usr << "\red Name too long."
return
var/area/A = new
A.name = str
@@ -149,8 +149,8 @@ move an amendment to the drawing.
/obj/item/blueprints/proc/edit_area()
var/area/A = get_area()
//world << "DEBUG: edit_area"
- var/prevname = A.name
- var/str = trim(stripped_input(usr,"New area title","Blueprints editing", prevname, MAX_NAME_LEN))
+ var/prevname = "[A.name]"
+ var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", prevname, MAX_NAME_LEN))
if(!str || !length(str) || str==prevname) //cancel
return
if(length(str) > 50)
diff --git a/code/game/objects/items/devices/uplinks.dm b/code/game/objects/items/devices/uplinks.dm
index 16a29af3098..8fc01b02ba8 100644
--- a/code/game/objects/items/devices/uplinks.dm
+++ b/code/game/objects/items/devices/uplinks.dm
@@ -85,7 +85,7 @@ A list of items and costs is stored under the datum of every game mode, alongsid
if (href_list["buy_item"])
var/item = href_list["buy_item"]
- var/list/split = stringsplit(item, ":") // throw away variable
+ var/list/split = text2list(item, ":") // throw away variable
if(split.len == 2)
// Collect category and number
diff --git a/code/game/objects/structures/transit_tubes.dm b/code/game/objects/structures/transit_tubes.dm
index 41bde491118..d756f380baf 100644
--- a/code/game/objects/structures/transit_tubes.dm
+++ b/code/game/objects/structures/transit_tubes.dm
@@ -576,7 +576,7 @@ obj/structure/ex_act(severity)
if(text in direction_table)
return direction_table[text]
- var/list/split_text = stringsplit(text, "-")
+ var/list/split_text = text2list(text, "-")
// If the first token is D, the icon_state represents
// a purely decorative tube, and doesn't actually
diff --git a/code/modules/admin/create_mob.dm b/code/modules/admin/create_mob.dm
index 6e642d8aca7..a723fe37956 100644
--- a/code/modules/admin/create_mob.dm
+++ b/code/modules/admin/create_mob.dm
@@ -2,7 +2,7 @@
/datum/admins/proc/create_mob(var/mob/user)
if (!create_mob_html)
var/mobjs = null
- mobjs = dd_list2text(typesof(/mob), ";")
+ mobjs = list2text(typesof(/mob), ";")
create_mob_html = file2text('html/create_object.html')
create_mob_html = replacetext(create_mob_html, "null /* object types */", "\"[mobjs]\"")
diff --git a/code/modules/admin/create_object.dm b/code/modules/admin/create_object.dm
index 73e7cef9199..5b5f926e4b1 100644
--- a/code/modules/admin/create_object.dm
+++ b/code/modules/admin/create_object.dm
@@ -3,7 +3,7 @@
/datum/admins/proc/create_object(var/mob/user)
if (!create_object_html)
var/objectjs = null
- objectjs = dd_list2text(typesof(/obj), ";")
+ objectjs = list2text(typesof(/obj), ";")
create_object_html = file2text('html/create_object.html')
create_object_html = replacetext(create_object_html, "null /* object types */", "\"[objectjs]\"")
@@ -21,7 +21,7 @@
if (!quick_create_object_html)
var/objectjs = null
- objectjs = dd_list2text(typesof(path), ";")
+ objectjs = list2text(typesof(path), ";")
quick_create_object_html = file2text('html/create_object.html')
quick_create_object_html = replacetext(quick_create_object_html, "null /* object types */", "\"[objectjs]\"")
diff --git a/code/modules/admin/create_turf.dm b/code/modules/admin/create_turf.dm
index 56f719b47d1..0938b7bd33d 100644
--- a/code/modules/admin/create_turf.dm
+++ b/code/modules/admin/create_turf.dm
@@ -2,7 +2,7 @@
/datum/admins/proc/create_turf(var/mob/user)
if (!create_turf_html)
var/turfjs = null
- turfjs = dd_list2text(typesof(/turf), ";")
+ turfjs = list2text(typesof(/turf), ";")
create_turf_html = file2text('html/create_object.html')
create_turf_html = replacetext(create_turf_html, "null /* object types */", "\"[turfjs]\"")
diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm
index 4da07ab731c..67f9c0fac6d 100644
--- a/code/modules/admin/topic.dm
+++ b/code/modules/admin/topic.dm
@@ -1471,7 +1471,7 @@
alert("Select fewer object types, (max 5)")
return
else if(length(removed_paths))
- alert("Removed:\n" + dd_list2text(removed_paths, "\n"))
+ alert("Removed:\n" + list2text(removed_paths, "\n"))
var/list/offset = text2list(href_list["offset"],",")
var/number = dd_range(1, 100, text2num(href_list["object_count"]))
diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm
index 197756fefc7..6b06342dee7 100644
--- a/code/modules/admin/verbs/debug.dm
+++ b/code/modules/admin/verbs/debug.dm
@@ -1066,16 +1066,16 @@ var/global/list/g_fancy_list_of_safe_types = null
switch(input("Which list?") in list("Players","Admins","Mobs","Living Mobs","Dead Mobs","Clients","Joined Clients"))
if("Players")
- usr << dd_list2text(player_list,",")
+ usr << list2text(player_list,",")
if("Admins")
- usr << dd_list2text(admins,",")
+ usr << list2text(admins,",")
if("Mobs")
- usr << dd_list2text(mob_list,",")
+ usr << list2text(mob_list,",")
if("Living Mobs")
- usr << dd_list2text(living_mob_list,",")
+ usr << list2text(living_mob_list,",")
if("Dead Mobs")
- usr << dd_list2text(dead_mob_list,",")
+ usr << list2text(dead_mob_list,",")
if("Clients")
- usr << dd_list2text(clients,",")
+ usr << list2text(clients,",")
if("Joined Clients")
- usr << dd_list2text(joined_player_list,",")
+ usr << list2text(joined_player_list,",")
diff --git a/code/modules/clothing/masks/gasmask.dm b/code/modules/clothing/masks/gasmask.dm
index 91e10749606..74a3eab0ac7 100644
--- a/code/modules/clothing/masks/gasmask.dm
+++ b/code/modules/clothing/masks/gasmask.dm
@@ -211,7 +211,7 @@
if(findtext(temp_message[H], "*") || findtext(temp_message[H], ";") || findtext(temp_message[H], ":")) continue
temp_message[H] = ninjaspeak(temp_message[H])
pick_list -= H
- message = dd_list2text(temp_message, " ")
+ message = list2text(temp_message, " ")
message = replacetext(message, "o", "¤")
message = replacetext(message, "p", "þ")
message = replacetext(message, "l", "£")
diff --git a/code/modules/detectivework/scanner.dm b/code/modules/detectivework/scanner.dm
index 771aa9a77d2..daf2d5de74b 100644
--- a/code/modules/detectivework/scanner.dm
+++ b/code/modules/detectivework/scanner.dm
@@ -24,7 +24,7 @@
var/obj/item/weapon/paper/P = new(get_turf(src))
P.name = "paper- 'Scanner Report'"
P.info = "Scanner Report
"
- P.info += dd_list2text(log, "
")
+ P.info += list2text(log, "
")
P.info += "
Notes:
"
P.info_links = P.info
diff --git a/code/modules/flufftext/TextFilters.dm b/code/modules/flufftext/TextFilters.dm
index 1447ac7662a..6481c336ac1 100644
--- a/code/modules/flufftext/TextFilters.dm
+++ b/code/modules/flufftext/TextFilters.dm
@@ -57,7 +57,7 @@ proc/NewStutter(phrase,stunned)
split_phrase[index] = word
- return sanitize(dd_list2text(split_phrase," "))
+ return sanitize(list2text(split_phrase," "))
proc/Stagger(mob/M,d) //Technically not a filter, but it relates to drunkenness.
step(M, pick(d,turn(d,90),turn(d,-90)))
@@ -78,6 +78,6 @@ proc/Ellipsis(original_msg, chance = 50)
else
new_words += w
- new_msg = dd_list2text(new_words," ")
+ new_msg = list2text(new_words," ")
return new_msg
diff --git a/code/modules/mob/living/carbon/human/say.dm b/code/modules/mob/living/carbon/human/say.dm
index 73a7961d649..74e0dbc8f9f 100644
--- a/code/modules/mob/living/carbon/human/say.dm
+++ b/code/modules/mob/living/carbon/human/say.dm
@@ -52,7 +52,7 @@
if(findtext(temp_message[H], "*") || findtext(temp_message[H], ";") || findtext(temp_message[H], ":")) continue
temp_message[H] = "HONK"
pick_list -= H //Make sure that you dont HONK the same word twice
- message = dd_list2text(temp_message, " ")
+ message = list2text(temp_message, " ")
if(wear_mask)
message = wear_mask.speechModification(message)
diff --git a/code/modules/mob/living/silicon/ai/say.dm b/code/modules/mob/living/silicon/ai/say.dm
index 7e28b4f111f..c3e8db720c1 100644
--- a/code/modules/mob/living/silicon/ai/say.dm
+++ b/code/modules/mob/living/silicon/ai/say.dm
@@ -87,7 +87,7 @@ var/const/VOX_DELAY = 600
src << "Wireless interface disabled, unable to interact with announcement PA."
return
- var/list/words = stringsplit(trim(message), " ")
+ var/list/words = text2list(trim(message), " ")
var/list/incorrect_words = list()
if(words.len > 30)
diff --git a/code/world.dm b/code/world.dm
index 00d45043c40..d182b01a9fe 100644
--- a/code/world.dm
+++ b/code/world.dm
@@ -284,7 +284,7 @@
features += "hosted by [config.hostedby]"
if (features)
- s += ": [dd_list2text(features, ", ")]"
+ s += ": [list2text(features, ", ")]"
/* does this help? I do not know */
if (src.status != s)
From 50cbc0ac29fc87286f8121a39f7f3de13efcdfa2 Mon Sep 17 00:00:00 2001
From: YotaXP
Date: Wed, 8 Jan 2014 23:03:43 -0500
Subject: [PATCH 2/3] Fixed a major bug. Improved speed further.
---
code/__HELPERS/type2type.dm | 106 +++++++++++++++++++-----------------
1 file changed, 57 insertions(+), 49 deletions(-)
diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm
index 48ee97fc180..9f08006cdf7 100644
--- a/code/__HELPERS/type2type.dm
+++ b/code/__HELPERS/type2type.dm
@@ -63,44 +63,49 @@
// Concatenates a list of strings into a single string. A seperator may optionally be provided.
/proc/list2text(list/ls, sep)
- if(ls.len <= 1) return ls.len ? ls[1] : ""
- . = ""
- var/l = ls.len
- var/i = 0
+ if(ls.len <= 1) // Early-out code for empty or singleton lists.
+ return ls.len ? ls[1] : ""
- if(sep)
- #define S1 ls[++i]
- #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
+ var/l = ls.len // Made local for sanic speed.
+ var/i = 0 // Incremented every time a list index is accessed.
- while(l-i >= 128)
- . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, sep, S64)
- if(l-i >= 64)
- . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ if(sep <> null)
+ // 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.
+
+ // Having the small concatenations come before the large ones boosted speed by an average of at least 5%.
+ 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)
- if(l-i >= 32)
- . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
- [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, sep, S16)
- if(l-i >= 16)
- . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
- if(l-i >= 8)
- . = text("[][][][][][][][][][][][][][][][]", ., S4, sep, S4)
- if(l-i >= 4)
- . = text("[][][][][][][][]", ., S4)
- if(l-i >= 2)
- . = text("[][][][]", ., S1, sep, S1)
- if(l > i)
- . = text("[][][]", ., sep, S1)
+ while(l > i) // Chomp through the rest of the list, 128 elements at a time.
+ . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
+ [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
#undef S64
#undef S16
@@ -108,31 +113,34 @@
#undef S1
else
+ // Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
#define S1 ls[++i]
#define S4 S1, S1, S1, S1
#define S16 S4, S4, S4, S4
#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("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., 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 S16
From cb0516f90911cc7a17858c142658425ad252cf0a Mon Sep 17 00:00:00 2001
From: YotaXP
Date: Sat, 11 Jan 2014 12:51:42 -0500
Subject: [PATCH 3/3] Corrected my own grammar failings.
---
code/__HELPERS/type2type.dm | 2 +-
code/game/objects/items/blueprints.dm | 24 ++++++++++++------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm
index 9f08006cdf7..402d9d805c3 100644
--- a/code/__HELPERS/type2type.dm
+++ b/code/__HELPERS/type2type.dm
@@ -69,7 +69,7 @@
var/l = ls.len // Made local for sanic speed.
var/i = 0 // Incremented every time a list index is accessed.
- if(sep <> null)
+ if(sep != null)
// 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
diff --git a/code/game/objects/items/blueprints.dm b/code/game/objects/items/blueprints.dm
index 85898b029fb..152377dff1c 100644
--- a/code/game/objects/items/blueprints.dm
+++ b/code/game/objects/items/blueprints.dm
@@ -21,7 +21,7 @@
/obj/item/blueprints/attack_self(mob/M as mob)
if (!istype(M,/mob/living/carbon/human))
- M << "This stack of blue paper means nothing to you." //monkeys cannot into projecting
+ M << "This stack of blue paper means nothing to you." //monkeys cannot into projecting
return
interact()
return
@@ -53,18 +53,18 @@
switch (get_area_type())
if (AREA_SPACE)
text += {"
-According the blueprints, you are now in outer space. Hold your breath.
+According to the blueprints, you are now in outer space. Hold your breath.
Mark this place as new area.
"}
if (AREA_STATION)
text += {"
-According the blueprints, you are now in \"[A.name]\".
+According to the blueprints, you are now in \"[A.name]\".
You may
move an amendment to the drawing.
"}
if (AREA_SPECIAL)
text += {"
-This place isn't noted on the blueprint.
+This place is not noted on the blueprint.
"}
else
return
@@ -105,20 +105,20 @@ move an amendment to the drawing.
if(!istype(res,/list))
switch(res)
if(ROOM_ERR_SPACE)
- usr << "\red The new area must be completely airtight!"
+ usr << "The new area must be completely airtight."
return
if(ROOM_ERR_TOOLARGE)
- usr << "\red The new area too large!"
+ usr << "The new area is too large."
return
else
- usr << "\red Error! Please notify administration!"
+ usr << "Error! Please notify administration."
return
var/list/turf/turfs = res
- var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", "", MAX_NAME_LEN))
+ var/str = trim(stripped_input(usr,"New area name:", "Blueprint Editing", "", MAX_NAME_LEN))
if(!str || !length(str)) //cancel
return
if(length(str) > 50)
- usr << "\red Name too long."
+ usr << "The given name is too long. The area remains undefined."
return
var/area/A = new
A.name = str
@@ -150,16 +150,16 @@ move an amendment to the drawing.
var/area/A = get_area()
//world << "DEBUG: edit_area"
var/prevname = "[A.name]"
- var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", prevname, MAX_NAME_LEN))
+ var/str = trim(stripped_input(usr,"New area name:", "Blueprint Editing", prevname, MAX_NAME_LEN))
if(!str || !length(str) || str==prevname) //cancel
return
if(length(str) > 50)
- usr << "\red Text too long."
+ usr << "The given name is too long. The area's name is unchanged."
return
set_area_machinery_title(A,str,prevname)
for(var/area/RA in A.related)
RA.name = str
- usr << "\blue You set the area '[prevname]' title to '[str]'."
+ usr << "You rename the '[prevname]' to '[str]'."
interact()
return