mirror of
https://github.com/nodejs/node.git
synced 2026-12-05 05:08:50 -05:00
src: prefer data accessor of string and vector
The pattern of getting the address of the element at index 0 of a container is generally used to materialize a pointer to the backing data of a container, however `std::string` and `std::vector` provide a `data()` accessor to retrieve the data pointer which should be preferred. This also ensures that in the case that the container is empty, the data pointer access does not perform an errant memory access. PR-URL: https://github.com/nodejs/node/pull/47750 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
456fca0d9c
commit
b04d51a0b5
8 files changed
+15
-14
No files matched your search
+1
-1
@@ -541,7 +541,7 @@ size_t StringBytes::hex_encode(
|
||||
std::string StringBytes::hex_encode(const char* src, size_t slen) {
|
||||
size_t dlen = slen * 2;
|
||||
std::string dst(dlen, '\0');
|
||||
hex_encode(src, slen, &dst[0], dlen);
|
||||
hex_encode(src, slen, dst.data(), dlen);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user