@whitequark wakers[:] = (waker for waker in wakers if waker(*va_args))
@val oh, interesting! this does basically the same amount of allocation, right?
@whitequark probably, yes
@val actually I don't think that can be the case, or it would break whenever you expand the list
@whitequark indeed, it looks like this materializes the iterable: https://github.com/python/cpython/blob/c7c9b913c01afb8d2ff4048f82155969f7ef75b1/Objects/listobject.c#L891
sad
wakers[:] = [waker for waker in wakers if waker(*va_args)]
`?@whitequark This should have the same memory properties as the original:
for index, waker in enumerate(waker for waker in wakers if waker(*args)):
wakers[index] = waker
del wakers[index + 1:]
Not sure if it's more readable or if I'm just liner golfing. I'm also not thrilled with using index
outside the loop, I actually wish that wouldn't be in scope.Yeah, there are more objects created and I imagine the generator protocol calls aren't cheap.
Oops also it would break if the filtered list were empty. Guarding it by adding index = -1
before removes the golf benefit.
Once again, explicit is better.
@whitequark OT: my brain is apparently incapable of not reading "wakers" as a slightly differently spelled noun..
@whitequark
> va_args
I think I've seen this somewhere, perhaps C?
Also, I think you've just shown me what wakers are, but I still don't fully understand
@sanfierro yes
i'm making a kind of obscure joke where i took some Python that reads similar to C code, and made it look a bit more like C code
@whitequark after the setup I was sure the improvement was going to be an ‘n’