Created
April 29, 2013 18:12
-
-
Save zah/5483516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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