Skip to content

Instantly share code, notes, and snippets.

@zah
Created April 29, 2013 18:12
Show Gist options
  • Select an option

  • Save zah/5483516 to your computer and use it in GitHub Desktop.

Select an option

Save zah/5483516 to your computer and use it in GitHub Desktop.
var globalFiles: seq[FileInfo]
proc getFileName(i: int): string =
return globalFiles[i].name # unnecessary copy (life-time of the global exceeds any caller score)
type
TFoo = object
data: string
TBar = object
sortedFoos: seq[TFoo]
proc FindFooFata(b: TBar): string =
...
return b.sortedFoos[12].data # unnecessary copy
# (the final value is effectively owned by the 'b' param and its lifetime
# is guaranteed to be within the bounds of the 'b' lifetime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment