spacepaste

  1.  
  2. # API option 1
  3. # Assume this is implemented as a small bit of rpython
  4. # Returns a list object; almost always empty
  5. def get_queued_items():
  6. return [...]
  7. # App-level usage:
  8. items = get_queued_items()
  9. if items:
  10. # do something rare and expensive
  11. ...
  12. # API option 2
  13. # Assume these are both implemented as small bits of rpython
  14. def has_queued_items():
  15. return bool(...)
  16. def get_queued_items():
  17. return [...]
  18. # App-level usage:
  19. if has_queued_items():
  20. # do something rare and expensive
  21. items = get_queued_items()
  22. ...
  23. # Question: API option 2 naively seems a bit easier for the JIT to optimize, because it's "obvious"
  24. # that you don't need to allocate a list object etc. Is that true?
  25. #
  26. # Or is it trivial for the JIT to optimize option 1 into the same thing as it would do for
  27. # option 2?
  28.