mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

373K
active users

✧✦✶✷Catherine✷✶✦✧

wrote some CPython code today

@whitequark wakers[:] = (waker for waker in wakers if waker(*va_args))

@val oh, interesting! this does basically the same amount of allocation, right?

@val actually I don't think that can be the case, or it would break whenever you expand the list

@val @whitequark You mean it becomes equivalent to `wakers[:] = [waker for waker in wakers if waker(*va_args)]`?

@clacke @val basically yes, as far as i can tell from the code

@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.

@val

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 @val

@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’