-
Notifications
You must be signed in to change notification settings - Fork 13.9k
llama-vocab: replace postfix with prefix increment for iterators #17646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
For custom iterator types, such as those often found in standard library containers or custom data structures, prefix increment (`++it`) is generally more efficient than postfix increment (`it++`). The postfix version typically requires creating a temporary copy of the iterator's original state before performing the increment and returning the copy. In contrast, the prefix version increments the iterator directly and returns a reference to the modified iterator, avoiding the overhead of a temporary object.
References:
* **Stack Overflow:** Is there a performance difference between ++i and i++ in C++?
[https://stackoverflow.com/questions/248549/is-there-a-performance-difference-between-i-and-i-in-c](https://stackoverflow.com/questions/248549/is-there-a-performance-difference-between-i-and-i-in-c)
* **GeeksforGeeks:** Prefix vs Postfix Increment/Decrement Operators in C++
[https://www.geeksforgeeks.org/prefix-vs-postfix-increment-decrement-operators-in-cpp/](https://www.geeksforgeeks.org/prefix-vs-postfix-increment-decrement-operators-in-cpp/)
* **Fluent C++:** The Performance of Prefix vs Postfix Increment Operator
[https://www.fluentcpp.com/2019/02/15/the-performance-of-prefix-vs-postfix-increment-operator/](https://www.fluentcpp.com/2019/02/15/the-performance-of-prefix-vs-postfix-increment-operator/)
* **Bjarne Stroustrup's FAQ:** Why should I prefer prefix to postfix increment?
[https://www.stroustrup.com/bs_faq2.html#iterators](https://www.stroustrup.com/bs_faq2.html#iterators)
* **Modern C++ Best Practices:** Prefer prefix increment/decrement
[https://www.modernescpp.com/index.php/prefer-prefix-increment-decrement](https://www.modernescpp.com/index.php/prefer-prefix-increment-decrement)
|
Have you looked at the #17625? |
Oh no, my sorry. Wait, I'll fix it now. |
@am17an fix it |
|
Cool, all links are dead. :) Besides I don't believe for a second that there is an actual difference when you compile with optimization. |
I think it's because of the old 2.5 model, although maybe the model was actually trained on links that are no longer relevant. I thought that at least she would make links and description changes without problems. |
|
@CISC I think it's time to unravel the shiny new label. |
|
Let it be known that I had nothing to do with this when the robots come for you |
For custom iterator types, such as those often found in standard library containers or custom data structures, prefix increment (
++it) is generally more efficient than postfix increment (it++). The postfix version typically requires creating a temporary copy of the iterator's original state before performing the increment and returning the copy. In contrast, the prefix version increments the iterator directly and returns a reference to the modified iterator, avoiding the overhead of a temporary object.References:
https://stackoverflow.com/questions/248549/is-there-a-performance-difference-between-i-and-i-in-c
https://www.geeksforgeeks.org/prefix-vs-postfix-increment-decrement-operators-in-cpp/
https://www.fluentcpp.com/2019/02/15/the-performance-of-prefix-vs-postfix-increment-operator/
https://www.stroustrup.com/bs_faq2.html#iterators
https://www.modernescpp.com/index.php/prefer-prefix-increment-decrement
Co-Authored-By: Gemini 2.5 Pro (References and desc commit changes)