Skip to content

Conversation

nordlow
Copy link
Contributor

@nordlow nordlow commented Sep 6, 2025

No description provided.

@nordlow nordlow requested a review from CyberShadow as a code owner September 6, 2025 13:09
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @nordlow! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#10856"

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You appear to have converted all spaces to tabs.

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the new parameter to the documentation comments

@nordlow
Copy link
Contributor Author

nordlow commented Sep 6, 2025

Need to remove whitespace changes. Hang on.

@nordlow nordlow force-pushed the read-with-appendNullTerminator branch from a760bd2 to 1a9765e Compare September 6, 2025 15:31
@CyberShadow
Copy link
Member

Hi @nordlow ,

Would be interesting to know so that we can evaluate adding this:

  • What use case have you encountered that led you to propose this addition?
  • Do you think it's a common enough use case to warrant adding it to the standard library? If so, why?
  • Do any other programming languages or frameworks have a similar option in the standard library? If so, which? If not, why do you think D's standard library should do something inordinary?

@thewilsonator I think addition of new parameters which implement new features should be treated in the same way as addition of new symbols. Does that still need BDFL approval?

@CyberShadow
Copy link
Member

One way we can approach this is to just do this unconditionally; then, we don't need a new option to take up space in the argument list. It would mean allocating one extra byte when reading files, which is a negligible overhead. For empty files, we can return "" (the empty string literal) to avoid allocation.

@nordlow
Copy link
Contributor Author

nordlow commented Sep 7, 2025

One way we can approach this is to just do this unconditionally; then, we don't need a new option to take up space in the argument list. It would mean allocating one extra byte when reading files, which is a negligible overhead. For empty files, we can return "" (the empty string literal) to avoid allocation.

Agreed. Turns out the extra byte at the end is already allocated in the master version of readImpl. So then we just need to document this behavior and add a test verifying the null terminator at the end.

@nordlow
Copy link
Contributor Author

nordlow commented Sep 7, 2025

The motive for adding the null at the end is that it enables sentinel-based search in lexers. Being somewhat of a forgotten technique for increasing the speed of lexers and in turn parsers and scanners. Andrei Alexandrescu has talked about this previously on at least occation. I believe he used the term "sentinel-based search", IRC. FYI, @andralex.

@atilaneves
Copy link
Contributor

The whitespace changes make it nigh impossible to find where the actual changes are, so I don't know what the diff should be. Having said, the title of the MR makes me question why this would be desired.

@nordlow
Copy link
Contributor Author

nordlow commented Sep 9, 2025

Having said, the title of the MR makes me question why this would be desired.

Did you read #10856 (comment)?

@atilaneves
Copy link
Contributor

Having said, the title of the MR makes me question why this would be desired.

Did you read #10856 (comment)?

Yes, but why can't the user append it if they want to?

@rikkimax
Copy link
Contributor

Having said, the title of the MR makes me question why this would be desired.

Did you read #10856 (comment)?

Yes, but why can't the user append it if they want to?

Can and should are two different things.

If you do it when you're dealing with buffers like read/readText should be, it can be free.

If the user does it outside of the buffer handling, that is very much not free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants