# HG changeset patch # User Kim Alvefur # Date 1443192302 -7200 # Node ID 0455b9686e166a3639e594ac88909750b4eead36 # Parent 32327c80710bafff411c07fbbf4da9186fcb60e1 server_event: Replace implementation of ordered set with a simple table set diff -r 32327c80710b -r 0455b9686e16 net/server_event.lua --- a/net/server_event.lua Fri Sep 25 15:16:25 2015 +0200 +++ b/net/server_event.lua Fri Sep 25 16:45:02 2015 +0200 @@ -33,7 +33,7 @@ } local function use(x) return rawget(_G, x); end -local ipairs = use "ipairs" +local pairs = use "pairs" local string = use "string" local select = use "select" local require = use "require" @@ -82,35 +82,7 @@ local EV_READWRITE = bitor( EV_READ, EV_WRITE ) -local interfacelist = ( function( ) -- holds the interfaces for sockets - local array = { } - local len = 0 - return function( method, arg ) - if "add" == method then - len = len + 1 - array[ len ] = arg - arg:_position( len ) - return len - elseif "delete" == method then - if len <= 0 then - return nil, "array is already empty" - end - local position = arg:_position() -- get position in array - if position ~= len then - local interface = array[ len ] -- get last interface - array[ position ] = interface -- copy it into free position - array[ len ] = nil -- free last position - interface:_position( position ) -- set new position in array - else -- free last position - array[ len ] = nil - end - len = len - 1 - return len - else - return array - end - end -end )( ) +local interfacelist = { } -- Client interface methods local interface_mt @@ -121,10 +93,6 @@ local coroutine_wrap, coroutine_yield = coroutine.wrap,coroutine.yield -- Private methods - function interface_mt:_position(new_position) - self.position = new_position or self.position - return self.position; - end function interface_mt:_close() return self:_destroy(); end @@ -266,7 +234,7 @@ self.eventread, self.eventclose = nil, nil self.interface, self.readcallback = nil, nil end - interfacelist( "delete", self ) + interfacelist[ self ] = nil return true end @@ -644,7 +612,7 @@ client:settimeout( 0 ) -- set non blocking setmetatable(interface, interface_mt) - interfacelist( "add", interface ) -- add to interfacelist + interfacelist[ interface ] = true -- add to interfacelist return interface end end @@ -710,7 +678,7 @@ server:settimeout( 0 ) setmetatable(interface, interface_mt) - interfacelist( "add", interface ) + interfacelist[ interface ] = true interface:_start_session() return interface end @@ -795,7 +763,7 @@ end )( ) local closeallservers = function( arg ) - for _, item in ipairs( interfacelist( ) ) do + for item in pairs( interfacelist ) do if item.type == "server" then item:close( arg ) end