phobos
phobos copied to clipboard
add fromHexString
As I understood Phobos does not contain any functions for converting text strings to byte array
hexString - template(not usable in runtime parse, to - cannot convert into byte array
Thanks for your pull request and interest in making D better, @Tynukua! 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:
andReturns:
)
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#8523"
Just a high-level observation: having toDigest return a range would avoid the gc allocation.
I don't get you It already does not contains GC allocation for static arrays
I don't get you
The first overload allocates with the gcc. My point was that toDigestImpl
may return a range that lazily computes the bytes when needed. Isn't that possible?
I don't get you
The first overload allocates with the gcc. My point was that
toDigestImpl
may return a range that lazily computes the bytes when needed. Isn't that possible?
Do you mean I should calculate the count of bytes to allocate more accurately?
No, I mean you could implement a ByteRange
that lazily computes the bytes:
struct ByteRange
{
string hexString; // stores a reference to the hex string that needs to be digested
size_t pos;
bool empty() { return pos == hexString; }
ubyte front() { /* compute the next byte to be returned */ }
void popFront() {/* advance `pos` to the next hex number */}
// maybe add other range primitives as well to make it a more powerful range
}
Then toDigest
will return such a range and no gc allocation will be required. I noticed that other digest functions do not make use of ranges, however, I do not know if it is anything preventing them for doing so or people just didn't think about this. What do you think @atilaneves ?
In all likelihood they were written ages ago when allocating was all the rage. I don't think repeating the mistakes of the past makes sense.
@atilaneves Do you think this is a worthwhile addition?
@atilaneves i updated PR now it contains only generator
As I understood Phobos does not contain any functions for converting text strings to byte array
hexString - template(not usable in runtime parse, to - cannot convert into byte array
Why can't they convert to a byte array?
As I understood Phobos does not contain any functions for converting text strings to byte array hexString - template(not usable in runtime parse, to - cannot convert into byte array
Why can't they convert to a byte array?
Actually it's possible by to, but u need chunk your hexstring https://forum.dlang.org/thread/[email protected]
Where does this sit now with compiler support for casting to arrays?
https://dlang.org/changelog/pending.html#dmd.hexstring-cast
I think it was always possible to cast them to a byte array, which gets its range interface from std.array.
As I understood Phobos does not contain any functions for converting text strings to byte array hexString - template(not usable in runtime parse, to - cannot convert into byte array
Why can't they convert to a byte array?
Actually it's possible by to, but u need chunk your hexstring https://forum.dlang.org/thread/[email protected]
Why isn't the implementation in this PR the one using chunk in the forum, then?
Where does this sit now with compiler support for casting to arrays?
https://dlang.org/changelog/pending.html#dmd.hexstring-cast
I think it was always possible to cast them to a byte array, which gets its range interface from std.array.
it's compiler time feature sometimes you need proceed with hex string in runtime
Why isn't the implementation in this PR the one using chunk in the forum, then?
I thought @nogc solution will be better, but now i m not sure Have u any suggestions what implementation is better for std?
Why isn't the implementation in this PR the one using chunk in the forum, then?
I thought @nogc solution will be better, but now i m not sure Have u any suggestions what implementation is better for std?
Unless I'm missing something, the only thing that isn't @nogc
in the solution in the forum is .array
. Leave that out, and there's the implementation. Users can call .array
if they want to.
Unless I'm missing something, the only thing that isn't
@nogc
in the solution in the forum is.array
. Leave that out, and there's the implementation. Users can call.array
if they want to.
.array part only in example...