Skip to content

Commit d404893

Browse files
committed
Revert "re-implement my microopts on top of the new cleaned up tg versions"
This reverts commit 9177791.
1 parent 9177791 commit d404893

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

code/__HELPERS/sorts/sort_instance.dm

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
3232

3333

3434
/datum/sort_instance/proc/timSort(start, end)
35-
runBases.len = 0
36-
runLens.len = 0
35+
runBases.Cut()
36+
runLens.Cut()
3737

3838
var/remaining = end - start
3939

@@ -59,8 +59,8 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
5959
runLen = force
6060

6161
//add data about run to queue
62-
runBases += start
63-
runLens += runLen
62+
runBases.Add(start)
63+
runLens.Add(runLen)
6464

6565
//maybe merge
6666
mergeCollapse()
@@ -179,10 +179,8 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
179179
//This method is called each time a new run is pushed onto the stack.
180180
//So the invariants are guaranteed to hold for i<stackSize upon entry to the method
181181
/datum/sort_instance/proc/mergeCollapse()
182-
var/list/runBases = src.runBases
183-
var/list/runLens = src.runLens
184-
while(length(runBases) >= 2)
185-
var/n = length(runBases) - 1
182+
while(runBases.len >= 2)
183+
var/n = runBases.len - 1
186184
if(n > 1 && runLens[n-1] <= runLens[n] + runLens[n+1])
187185
if(runLens[n-1] < runLens[n+1])
188186
--n
@@ -196,10 +194,8 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
196194
//Merges all runs on the stack until only one remains.
197195
//Called only once, to finalise the sort
198196
/datum/sort_instance/proc/mergeForceCollapse()
199-
var/list/runBases = src.runBases
200-
var/list/runLens = src.runLens
201-
while(length(runBases) >= 2)
202-
var/n = length(runBases) - 1
197+
while(runBases.len >= 2)
198+
var/n = runBases.len - 1
203199
if(n > 1 && runLens[n-1] < runLens[n+1])
204200
--n
205201
mergeAt(n)
@@ -209,9 +205,6 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
209205
//Run i must be the penultimate or antepenultimate run on the stack
210206
//In other words, i must be equal to stackSize-2 or stackSize-3
211207
/datum/sort_instance/proc/mergeAt(i)
212-
var/list/runBases = src.runBases
213-
var/list/runLens = src.runLens
214-
var/list/L = src.L
215208
//ASSERT(runBases.len >= 2)
216209
//ASSERT(i >= 1)
217210
//ASSERT(i == runBases.len - 1 || i == runBases.len - 2)
@@ -586,26 +579,24 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
586579
return
587580

588581
var/minRun = minRunLength(remaining)
589-
var/list/runBases = src.runBases
590-
var/list/runLens = src.runLens
591582

592583
do
593584
var/runLen = (remaining <= minRun) ? remaining : minRun
594585

595586
binarySort(start, start+runLen, start)
596587

597588
//add data about run to queue
598-
runBases += start
599-
runLens += runLen
589+
runBases.Add(start)
590+
runLens.Add(runLen)
600591

601592
//Advance to find next run
602593
start += runLen
603594
remaining -= runLen
604595

605596
while(remaining > 0)
606597

607-
while(length(runBases) >= 2)
608-
var/n = length(runBases) - 1
598+
while(runBases.len >= 2)
599+
var/n = runBases.len - 1
609600
if(n > 1 && runLens[n-1] <= runLens[n] + runLens[n+1])
610601
if(runLens[n-1] < runLens[n+1])
611602
--n
@@ -615,17 +606,15 @@ GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
615606
else
616607
break //Invariant is established
617608

618-
while(length(runBases) >= 2)
619-
var/n = length(runBases) - 1
609+
while(runBases.len >= 2)
610+
var/n = runBases.len - 1
620611
if(n > 1 && runLens[n-1] < runLens[n+1])
621612
--n
622613
mergeAt2(n)
623614

624615
return L
625616

626617
/datum/sort_instance/proc/mergeAt2(i)
627-
var/list/runBases = src.runBases
628-
var/list/runLens = src.runLens
629618
var/list/L = src.L
630619
var/cursor1 = runBases[i]
631620
var/cursor2 = runBases[i+1]

0 commit comments

Comments
 (0)