cp
cp copied to clipboard
The optimization of locks in BBQuery
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