Skip to content

Commit 6af7b78

Browse files
addaleaxmarco-ippolito
authored andcommittedMay 3, 2024
src: add string_view overload to snapshot FromBlob
The `const std::vector<char>&` variant only delegates to a method that converts it to a `std::string_view` anyway, but adding this capability to the public API as well means that it’s easier to store snapshot data in embedding applications (because using `std::vector<>` enforces heap allocation and `std::string_view` does not). PR-URL: #52595 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 1e88e04 commit 6af7b78

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
 

‎src/api/embed_helpers.cc

+5
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ EmbedderSnapshotData::Pointer EmbedderSnapshotData::BuiltinSnapshotData() {
302302

303303
EmbedderSnapshotData::Pointer EmbedderSnapshotData::FromBlob(
304304
const std::vector<char>& in) {
305+
return FromBlob(std::string_view(in.data(), in.size()));
306+
}
307+
308+
EmbedderSnapshotData::Pointer EmbedderSnapshotData::FromBlob(
309+
std::string_view in) {
305310
SnapshotData* snapshot_data = new SnapshotData();
306311
CHECK_EQ(snapshot_data->data_ownership, SnapshotData::DataOwnership::kOwned);
307312
EmbedderSnapshotData::Pointer result{

‎src/node.h

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class EmbedderSnapshotData {
537537
// If the snapshot is invalid, this returns an empty pointer.
538538
static Pointer FromFile(FILE* in);
539539
static Pointer FromBlob(const std::vector<char>& in);
540+
static Pointer FromBlob(std::string_view in);
540541

541542
// Write this EmbedderSnapshotData object to an output file.
542543
// Calling this method will not close the FILE* handle.

0 commit comments

Comments
 (0)
Please sign in to comment.