document that multiple yield in inline iterator cause code bloat (#10553)
* document that multiple `yield` in inline iterator cause code duplication * doc: rule `Start types with a capital T` was deprecated
This commit is contained in:
parent
824f39b32e
commit
2b30998159
2 changed files with 10 additions and 3 deletions
|
|
@ -67,8 +67,8 @@ Coding Guidelines
|
||||||
* Max line length is 80 characters.
|
* Max line length is 80 characters.
|
||||||
* Provide spaces around binary operators if that enhances readability.
|
* Provide spaces around binary operators if that enhances readability.
|
||||||
* Use a space after a colon, but not before it.
|
* Use a space after a colon, but not before it.
|
||||||
* Start types with a capital ``T``, unless they are pointers/references which
|
* [deprecated] Start types with a capital ``T``, unless they are
|
||||||
start with ``P``.
|
pointers/references which start with ``P``.
|
||||||
|
|
||||||
See also the `API naming design <apis.html>`_ document.
|
See also the `API naming design <apis.html>`_ document.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3870,7 +3870,14 @@ First class iterators
|
||||||
There are 2 kinds of iterators in Nim: *inline* and *closure* iterators.
|
There are 2 kinds of iterators in Nim: *inline* and *closure* iterators.
|
||||||
An `inline iterator`:idx: is an iterator that's always inlined by the compiler
|
An `inline iterator`:idx: is an iterator that's always inlined by the compiler
|
||||||
leading to zero overhead for the abstraction, but may result in a heavy
|
leading to zero overhead for the abstraction, but may result in a heavy
|
||||||
increase in code size. Inline iterators are second class citizens;
|
increase in code size.
|
||||||
|
|
||||||
|
Caution: the body of a for loop over an inline iterator is inlined into
|
||||||
|
each ``yield`` statement appearing in the iterator code,
|
||||||
|
so ideally the code should be refactored to contain a single yield when possible
|
||||||
|
to avoid code bloat.
|
||||||
|
|
||||||
|
Inline iterators are second class citizens;
|
||||||
They can be passed as parameters only to other inlining code facilities like
|
They can be passed as parameters only to other inlining code facilities like
|
||||||
templates, macros and other inline iterators.
|
templates, macros and other inline iterators.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue