Bug 15162 – byDchar calls empty twice in a row

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-05T20:11:00Z
Last change time
2016-05-03T17:00:37Z
Keywords
performance
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2015-10-05T20:11:07Z
The following program: import std.utf; import core.stdc.stdio; struct S { bool empty() { printf("empty\n"); return !s.length; } @property char front() { printf("front\n"); return s[0]; } void popFront() { printf("popFront()\n"); s = s[1 .. $]; } string s; } void main() { auto s = S("hello"); auto r = s.byDchar(); r.empty; r.front; r.popFront(); r.empty; r.front; r.popFront(); } prints 'empty' twice: empty empty front popFront() empty empty front popFront() For efficiency, it should only call empty once per character.
Comment #1 by john.loughran.colvin — 2015-10-07T12:59:24Z
Comment #2 by dlang-bugzilla — 2015-10-15T19:21:16Z
(In reply to John Colvin from comment #1) > Not totally sure, but I think you're just seeing > https://github.com/D-Programming-Language/phobos/blob/master/std/utf.d#L1169 I think you're right, there's just one "empty" in a row with -release.
Comment #3 by jack — 2016-05-03T17:00:37Z
Because the root cause of this is are contracts, and therefore the issue disappears in release, I'm closing this.