-
- # API option 1
-
- # Assume this is implemented as a small bit of rpython
- # Returns a list object; almost always empty
- def get_queued_items():
- return [...]
-
- # App-level usage:
- items = get_queued_items()
- if items:
- # do something rare and expensive
- ...
-
- # API option 2
-
- # Assume these are both implemented as small bits of rpython
- def has_queued_items():
- return bool(...)
-
- def get_queued_items():
- return [...]
-
- # App-level usage:
- if has_queued_items():
- # do something rare and expensive
- items = get_queued_items()
- ...
-
- # Question: API option 2 naively seems a bit easier for the JIT to optimize, because it's "obvious"
- # that you don't need to allocate a list object etc. Is that true?
- #
- # Or is it trivial for the JIT to optimize option 1 into the same thing as it would do for
- # option 2?
-