wrote some CPython code today
Conversation
Notices
-
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:21 JST ✧✦✶✷Catherine✷✶✦✧ -
Embed this notice
val (val@oc.todon.fr)'s status on Monday, 06-May-2024 13:46:20 JST val @whitequark wakers[:] = (waker for waker in wakers if waker(*va_args))
clacke likes this. -
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:21 JST ✧✦✶✷Catherine✷✶✦✧ figured out how to improve it
clacke likes this. -
Embed this notice
clacke (clacke@libranet.de)'s status on Monday, 06-May-2024 13:46:24 JST clacke @val @whitequark You mean it becomes equivalent to `wakers[:] = [waker for waker in wakers if waker(*va_args)]`? -
Embed this notice
val (val@oc.todon.fr)'s status on Monday, 06-May-2024 13:46:26 JST val @whitequark indeed, it looks like this materializes the iterable: https://github.com/python/cpython/blob/c7c9b913c01afb8d2ff4048f82155969f7ef75b1/Objects/listobject.c#L891
sad
-
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:27 JST ✧✦✶✷Catherine✷✶✦✧ @val actually I don't think that can be the case, or it would break whenever you expand the list
In conversation permalink -
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:29 JST ✧✦✶✷Catherine✷✶✦✧ @val oh, interesting! this does basically the same amount of allocation, right?
In conversation permalink -
Embed this notice
val (val@oc.todon.fr)'s status on Monday, 06-May-2024 13:46:29 JST val @whitequark probably, yes
In conversation permalink -
Embed this notice
Steven Reed (srtcd424@mas.to)'s status on Monday, 06-May-2024 13:46:34 JST Steven Reed @whitequark OT: my brain is apparently incapable of not reading "wakers" as a slightly differently spelled noun..
In conversation permalink clacke likes this. -
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:39 JST ✧✦✶✷Catherine✷✶✦✧ @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
In conversation permalink clacke likes this. -
Embed this notice
sanfierro (sanfierro@pony.social)'s status on Monday, 06-May-2024 13:46:40 JST sanfierro @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 understandIn conversation permalink -
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:54 JST ✧✦✶✷Catherine✷✶✦✧ In conversation permalink -
Embed this notice
clacke (clacke@libranet.de)'s status on Monday, 06-May-2024 13:46:54 JST clacke 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.
In conversation permalink -
Embed this notice
clacke (clacke@libranet.de)'s status on Monday, 06-May-2024 13:46:55 JST clacke @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.In conversation permalink -
Embed this notice
✧✦✶✷Catherine✷✶✦✧ (whitequark@mastodon.social)'s status on Monday, 06-May-2024 13:46:56 JST ✧✦✶✷Catherine✷✶✦✧ @clacke @val basically yes, as far as i can tell from the code
In conversation permalink
-
Embed this notice