Skip to content

Commit

Permalink
rename set to fill since set already was a function
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Dec 4, 2010
1 parent ba4dec3 commit 1f250a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ Buffer.prototype.toString = function (encoding, start, end) {
Buffer.byteLength = SlowBuffer.byteLength;


// set(value, start=0, end=buffer.length)
Buffer.prototype.set = function set (value, start, end) {
// fill(value, start=0, end=buffer.length)
Buffer.prototype.fill = function fill (value, start, end) {
value || (value = 0);
start || (start = 0);
end || (end = this.length);
Expand All @@ -295,7 +295,7 @@ Buffer.prototype.set = function set (value, start, end) {

if (end < start) throw new Error("end < start");

// Set 0 bytes; we're done
// Fill 0 bytes; we're done
if (end === start) return 0;
if (this.length == 0) return 0;

Expand All @@ -307,9 +307,9 @@ Buffer.prototype.set = function set (value, start, end) {
throw new Error("end out of bounds");
}

return this.parent.set(value,
start + this.offset,
end + this.offset);
return this.parent.fill(value,
start + this.offset,
end + this.offset);
};


Expand Down
6 changes: 3 additions & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
}


// buffer.set(value, start, end);
Handle<Value> Buffer::Set(const Arguments &args) {
// buffer.fill(value, start, end);
Handle<Value> Buffer::Fill(const Arguments &args) {
HandleScope scope;

if (!args[0]->IsInt32()) {
Expand Down Expand Up @@ -673,7 +673,7 @@ void Buffer::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "asciiWrite", Buffer::AsciiWrite);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "binaryWrite", Buffer::BinaryWrite);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "base64Write", Buffer::Base64Write);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "set", Buffer::Set);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fill", Buffer::Fill);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "copy", Buffer::Copy);

NODE_SET_METHOD(constructor_template->GetFunction(),
Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Buffer : public ObjectWrap {
static v8::Handle<v8::Value> Utf8Write(const v8::Arguments &args);
static v8::Handle<v8::Value> ByteLength(const v8::Arguments &args);
static v8::Handle<v8::Value> MakeFastBuffer(const v8::Arguments &args);
static v8::Handle<v8::Value> Set(const v8::Arguments &args);
static v8::Handle<v8::Value> Fill(const v8::Arguments &args);
static v8::Handle<v8::Value> Copy(const v8::Arguments &args);

Buffer(v8::Handle<v8::Object> wrapper, size_t length);
Expand Down
6 changes: 3 additions & 3 deletions test/simple/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,17 @@ assert.equal(12, Buffer.byteLength("Il était tué", "binary"));
assert.equal(0, Buffer('hello').slice(0, 0).length)

b = new Buffer(50);
b.set("h");
b.fill("h");
for (var i = 0; i < b.length; i++) {
assert.equal("h".charCodeAt(0), b[i]);
}

b.set(0);
b.fill(0);
for (var i = 0; i < b.length; i++) {
assert.equal(0, b[i]);
}

b.set(1, 16, 32);
b.fill(1, 16, 32);
for (var i = 0; i < 16; i++) assert.equal(0, b[i]);
for (; i < 32; i++) assert.equal(1, b[i]);
for (; i < b.length; i++) assert.equal(0, b[i]);

0 comments on commit 1f250a4

Please sign in to comment.