Skip to content

Commit 43fa6a1

Browse files
addaleaxaduh95
authored andcommitted
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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent b2f754c commit 43fa6a1

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
@@ -315,6 +315,11 @@ EmbedderSnapshotData::Pointer EmbedderSnapshotData::BuiltinSnapshotData() {
315315

316316
EmbedderSnapshotData::Pointer EmbedderSnapshotData::FromBlob(
317317
const std::vector<char>& in) {
318+
return FromBlob(std::string_view(in.data(), in.size()));
319+
}
320+
321+
EmbedderSnapshotData::Pointer EmbedderSnapshotData::FromBlob(
322+
std::string_view in) {
318323
SnapshotData* snapshot_data = new SnapshotData();
319324
CHECK_EQ(snapshot_data->data_ownership, SnapshotData::DataOwnership::kOwned);
320325
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)