Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Created January 28, 2019 07:12
Show Gist options
  • Save cleverca22/43344a86c25f833e3b804788a8c0cd92 to your computer and use it in GitHub Desktop.
Save cleverca22/43344a86c25f833e3b804788a8c0cd92 to your computer and use it in GitHub Desktop.

attrset ? "key" and attrset.key or fallback have nearly equal complexity costs

if attrset ? "key" then attrset.key else fallback is slightly more expensive,

due to being 3 AST nodes (an ExprIf with an ExprOpHasAttr as the condition and then an ExprSelect to extract the "key")

attrset.key or fallback is slightly cheaper, since it is a single AST node (just ExprSelect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment