GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: write strings directly from call · tcper/node@f5e13ae

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_buffer.cc
    • node_buffer.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ size_t Length(Handle<Object> obj) {
113113
}
114114

115115

116-
// TODO(trevnorris): would be more efficient to use StringBytes to calculate the
117-
// length and write out the data beforehand then do the same as New().
118-
Local<Object> New(Handle<String> string) {
116+
Local<Object> New(Handle<String> string, enum encoding enc) {
119117
HandleScope scope(node_isolate);
120118

121-
Handle<Value> argv[1] = { string };
122-
Local<Object> obj = p_buffer_fn->NewInstance(1, argv);
119+
size_t length = StringBytes::Size(string, enc);
123120

124-
return scope.Close(obj);
121+
Local<Object> buf = New(length);
122+
char* data = Buffer::Data(buf);
123+
StringBytes::Write(data, length, string, enc);
124+
125+
return scope.Close(buf);
125126
}
126127

127128

Collapse file

‎src/node_buffer.h‎

Copy file name to clipboardExpand all lines: src/node_buffer.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ NODE_EXTERN size_t Length(v8::Handle<v8::Object> val);
4242
// public constructor
4343
NODE_EXTERN v8::Local<v8::Object> New(size_t length);
4444
// public constructor from string
45-
NODE_EXTERN v8::Local<v8::Object> New(v8::Handle<v8::String> string);
45+
NODE_EXTERN v8::Local<v8::Object> New(v8::Handle<v8::String> string,
46+
enum encoding enc = UTF8);
4647
// public constructor - data is copied
4748
// TODO(trevnorris): should be something like Copy()
4849
NODE_EXTERN v8::Local<v8::Object> New(const char* data, size_t len);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.