Add index_from
argument to collidelistall
methods
#2917
Labels
enhancement
New API
This pull request may need extra debate as it adds a new class or function to pygame
Performance
Related to the speed or resource usage of the project
rect
pygame.rect
Currently the
Rect
's (and soonCircle
's) collidelistall methods return a list of indices of colliding objects. While this is very useful as an optimization over raw python looping (and generally over any other of our multicollision methods) I believe there's still a fundamental improvement still up for grabs here.What's usually done after calling
collidelistall()
is to immediately use the returned indices list to index into another container of any kind of object, usually the ones with corresponding rect object as collider.What I propose is to add an optional argument called
index_from
which saves the user from manually indexing the container again after the call and saves extra performance (about 40% from what I've tested internally). This would make code more performant, readable and compact.The text was updated successfully, but these errors were encountered: