-
-
Notifications
You must be signed in to change notification settings - Fork 740
Fix Issue 10662 - byLine!(Char, immutable Char) won't compile #1418
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
Conversation
@@ -1098,7 +1116,7 @@ Allows to directly use range operations on lines of a file. | |||
popFront(); | |||
first_call = false; | |||
} | |||
return line; | |||
return to!(Char[])(line); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just realized this will allocate a new string on each call to front
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you don't allocate a new string, that basically means you are going to clobber the returned string
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I did it, but I think repeated calls to front
without calling popFront
shouldn't keep making copies. Will fix.
Now fixed. |
@@ -1117,6 +1136,8 @@ Allows to directly use range operations on lines of a file. | |||
{ | |||
line = line.ptr[0 .. line.length - 1]; | |||
} | |||
// duplicate if necessary | |||
_front = to!(Char[])(line); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now fixed
Except now, you'll trigger a dupe even for normal ByLine!char
. Also, you might as well just call .dup
followed by a cast here. Who knows what to!
is doing (or not...) behind the scenes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. From http://dlang.org/phobos/std_conv.html#.to :
Converting a value to its own type (useful mostly for generic code) simply returns its argument.
you might as well just call .dup followed by a cast here
I would need a static if
. I think to
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum.... That might warrant an extra comment (IMO). But OK, works for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, this is an intended use case for to
- just use it and it'll do the right thing.
I'm not sure I agree with this "fix" (I explained why in your bug report). Having the behavior depend on the qualification of the input is weird for me: I think it would warrant a newly named function. If I understand you right, you are trying to do: char => reusable buffer: OK
immutable(char) => duped before returning buffer: I guess... why not?
const(char) => ??? I'm leaning in favor leaving |
This wouldn't compile because readln(buf) now requires a mutable buf. Make ByLine.line, ByLine.first_call private. Update unittest to test non-empty files without any newlines.
Changed to use As mentioned on the bug tracker, I'll probably start a discussion about improving |
See http://forum.dlang.org/post/ksj7b6$86b$1@digitalmars.com |
Closed as monarchdodra and jmdavis are opposed, plus |
http://d.puremagic.com/issues/show_bug.cgi?id=10662
This wouldn't compile because
readln(buf)
now requires a mutablebuf
.Also make
ByLine.line
,ByLine.first_call
private.