Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ents.FindByClassAndParent #2167

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
24 changes: 9 additions & 15 deletions garrysmod/lua/includes/extensions/ents.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@

function ents.FindByClassAndParent( classname, entity )

if ( !IsValid( entity ) ) then return end
if ( !IsValid( entity ) ) then return end

local list = ents.FindByClass( classname )
if ( !list ) then return end
local out = {}

local out = {}
for k, v in ipairs( list ) do
for k, v in ipairs( ents.FindByClass( classname ) ) do

if ( !IsValid(v) ) then continue end
if ( v:GetParent() == entity ) then
table.insert( out, v )
end

local p = v:GetParent()
if ( !IsValid(p) ) then continue end
if ( p != entity ) then continue end
end

table.insert( out, v )
if ( out[1] == nil ) then return end

end

if ( #out == 0 ) then return end

return out
return out

end

Expand Down