jakecoffman / cp

A pure Go physics library with no dependencies. Unofficial Chipmunk2D port.

Home Page:https://chipmunk-physics.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The optimization of locks in BBQuery

fananchong opened this issue · comments

Can

func (space *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{}) {
	context := BBQueryContext{bb, filter, f}
	space.Lock()

	space.staticShapes.class.Query(&context, bb, space.bbQuery, data)
	space.dynamicShapes.class.Query(&context, bb, space.bbQuery, data)

	space.Unlock(true)
}

be optimized to :

func (space *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{}) {
	context := BBQueryContext{bb, filter, f}

	space.staticShapes.class.Query(&context, bb, space.bbQuery, data)
	
	space.Lock()
	space.dynamicShapes.class.Query(&context, bb, space.bbQuery, data)
	space.Unlock(true)
}

Since this is a port, I'd rather not add optimizations unless it's first accepted upstream:

https://github.com/slembcke/Chipmunk2D/blob/d0239ef4599b3688a5a336373f7d0a68426414ba/src/cpSpaceQuery.c#L233-L246