Explorar o código

Stabilise sorting order

Every time this was run it would generate a different init.lua since
the table.sort() function isn't a stable sort and hence keys that don't
exist in the priority table can (and do) get rearranged since they all
have equal priority.
bobsayshilol %!s(int64=2) %!d(string=hai) anos
pai
achega
c9781a6fed
Modificáronse 2 ficheiros con 1054 adicións e 862 borrados
  1. 1043 861
      api/init.lua
  2. 11 1
      api/main.lua

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1043 - 861
api/init.lua


+ 11 - 1
api/main.lua

@@ -363,7 +363,17 @@ function lovr.load()
     returns = 9
   }
   local function sort(keys, t)
-    table.sort(keys, function(a, b) return (keyPriority[a] or 1000) < (keyPriority[b] or 1000) end)
+    table.sort(keys, function(lhs, rhs)
+      local leftPrio = keyPriority[lhs]
+      local rightPrio = keyPriority[rhs]
+      if leftPrio and rightPrio then
+        return leftPrio < rightPrio
+      elseif leftPrio or rightPrio then
+        return leftPrio ~= nil
+      else
+        return lhs < rhs
+      end
+    end)
   end
   local contents = 'return ' .. serpent.block(api, { comment = false, sortkeys = sort })
   file:write(contents)

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio