From 09b92c347fdc483198ebd19fccc35694cd1e215b Mon Sep 17 00:00:00 2001 From: StarSmasher Date: Sun, 10 May 2015 16:59:32 +0200 Subject: [PATCH] Optimises uniqueList() Credits go to /TG/, I just figured I'd do what the other codebases do and take it over for us as well. Changes: Optimises uniquelist() also renames it from uniquelist() to uniqueList() Test 1: 1,000,000 random numbers between 1 and 7 in a list. Clean out duplicates with current uniquelist(), once: self: 0.362 Clean out duplicates with my new uniqueList(), once: self: 0.184 Test 2: 3,000,000 random numbers between 1 and 7 in a list. Clean out duplicates with current uniquelist(), once: self: 1.069 Clean out duplicates with my new uniqueList(), once: self: 0.496 --- code/__HELPERS/lists.dm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index a1f13c18ab2..ed0f0c97809 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -182,11 +182,9 @@ proc/listclearnulls(list/list) //Return a list with no duplicate entries /proc/uniquelist(var/list/L) - var/list/K = list() - for(var/item in L) - if(!(item in K)) - K += item - return K + . = list() + for(var/i in L) + . |= i //Mergesort: divides up the list into halves to begin the sort /proc/sortKey(var/list/client/L, var/order = 1)