buffer: remove _charsWritten
_charsWritten is an internal property that was constantly written to, but never read from. So it has been removed. Removed documentation reference as well.
This commit is contained in:
parent
d20576165a
commit
ccda6bb3ac
@ -98,10 +98,6 @@ The method will not write partial characters.
|
||||
len = buf.write('\u00bd + \u00bc = \u00be', 0);
|
||||
console.log(len + " bytes: " + buf.toString('utf8', 0, len));
|
||||
|
||||
The number of characters written (which may be different than the number of
|
||||
bytes written) is set in `Buffer._charsWritten` and will be overwritten the
|
||||
next time `buf.write()` is called.
|
||||
|
||||
|
||||
### buf.toString([encoding], [start], [end])
|
||||
|
||||
|
@ -374,8 +374,6 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
|
||||
throw new TypeError('Unknown encoding: ' + encoding);
|
||||
}
|
||||
|
||||
Buffer._charsWritten = SlowBuffer._charsWritten;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
@ -60,7 +60,6 @@ using namespace v8;
|
||||
|
||||
|
||||
static Persistent<String> length_symbol;
|
||||
static Persistent<String> chars_written_sym;
|
||||
static Persistent<String> write_sym;
|
||||
static Persistent<Function> fast_buffer_constructor;
|
||||
Persistent<FunctionTemplate> Buffer::constructor_template;
|
||||
@ -591,8 +590,6 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
|
||||
int length = s->Length();
|
||||
|
||||
if (length == 0) {
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(0, node_isolate));
|
||||
return scope.Close(Integer::New(0, node_isolate));
|
||||
}
|
||||
|
||||
@ -614,10 +611,6 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
|
||||
(String::HINT_MANY_WRITES_EXPECTED |
|
||||
String::NO_NULL_TERMINATION));
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(char_written,
|
||||
node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(written, node_isolate));
|
||||
}
|
||||
|
||||
@ -652,9 +645,6 @@ Handle<Value> Buffer::Ucs2Write(const Arguments &args) {
|
||||
(String::HINT_MANY_WRITES_EXPECTED |
|
||||
String::NO_NULL_TERMINATION));
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(written, node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(written * 2, node_isolate));
|
||||
}
|
||||
|
||||
@ -687,7 +677,6 @@ Handle<Value> Buffer::HexWrite(const Arguments& args) {
|
||||
|
||||
if (start >= parent->length_) {
|
||||
Local<Integer> val = Integer::New(0, node_isolate);
|
||||
constructor_template->GetFunction()->Set(chars_written_sym, val);
|
||||
return scope.Close(val);
|
||||
}
|
||||
|
||||
@ -698,7 +687,6 @@ Handle<Value> Buffer::HexWrite(const Arguments& args) {
|
||||
|
||||
if (size == 0) {
|
||||
Local<Integer> val = Integer::New(0, node_isolate);
|
||||
constructor_template->GetFunction()->Set(chars_written_sym, val);
|
||||
return scope.Close(val);
|
||||
}
|
||||
|
||||
@ -718,9 +706,6 @@ Handle<Value> Buffer::HexWrite(const Arguments& args) {
|
||||
dst[i] = a * 16 + b;
|
||||
}
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(max * 2, node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(max, node_isolate));
|
||||
}
|
||||
|
||||
@ -755,9 +740,6 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
|
||||
(String::HINT_MANY_WRITES_EXPECTED |
|
||||
String::NO_NULL_TERMINATION));
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(written, node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(written, node_isolate));
|
||||
}
|
||||
|
||||
@ -818,10 +800,6 @@ Handle<Value> Buffer::Base64Write(const Arguments &args) {
|
||||
*dst++ = ((c & 0x03) << 6) | (d & 0x3F);
|
||||
}
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(dst - start,
|
||||
node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(dst - start, node_isolate));
|
||||
}
|
||||
|
||||
@ -851,9 +829,6 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
|
||||
|
||||
int written = DecodeWrite(p, max_length, s, BINARY);
|
||||
|
||||
constructor_template->GetFunction()->Set(chars_written_sym,
|
||||
Integer::New(written, node_isolate));
|
||||
|
||||
return scope.Close(Integer::New(written, node_isolate));
|
||||
}
|
||||
|
||||
@ -1118,7 +1093,6 @@ void Buffer::Initialize(Handle<Object> target) {
|
||||
assert(unbase64('\r') == -2);
|
||||
|
||||
length_symbol = NODE_PSYMBOL("length");
|
||||
chars_written_sym = NODE_PSYMBOL("_charsWritten");
|
||||
|
||||
Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New);
|
||||
constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
|
||||
|
@ -336,11 +336,8 @@ assert.deepEqual(f, new Buffer([252, 98, 101, 114]));
|
||||
var f = new Buffer([0, 0, 0, 0, 0]);
|
||||
assert.equal(f.length, 5);
|
||||
var size = f.write('あいうえお', encoding);
|
||||
var charsWritten = Buffer._charsWritten; // Copy value out.
|
||||
console.error('bytes written to buffer: %d (should be 4)', size);
|
||||
console.error('chars written to buffer: %d (should be 2)', charsWritten);
|
||||
assert.equal(size, 4);
|
||||
assert.equal(charsWritten, 2);
|
||||
assert.deepEqual(f, new Buffer([0x42, 0x30, 0x44, 0x30, 0x00]));
|
||||
});
|
||||
|
||||
@ -788,23 +785,6 @@ written = sub.write('12345', 'binary');
|
||||
assert.equal(written, 4);
|
||||
assert.equal(buf[4], 0);
|
||||
|
||||
// test for _charsWritten
|
||||
buf = new Buffer(9);
|
||||
buf.write('あいうえ', 'utf8'); // 3bytes * 4
|
||||
assert.equal(Buffer._charsWritten, 3);
|
||||
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
|
||||
buf.write('あいうえお', encoding); // 2bytes * 5
|
||||
assert.equal(Buffer._charsWritten, 4);
|
||||
});
|
||||
buf.write('0123456789', 'ascii');
|
||||
assert.equal(Buffer._charsWritten, 9);
|
||||
buf.write('0123456789', 'binary');
|
||||
assert.equal(Buffer._charsWritten, 9);
|
||||
buf.write('123456', 'base64');
|
||||
assert.equal(Buffer._charsWritten, 4);
|
||||
buf.write('00010203040506070809', 'hex');
|
||||
assert.equal(Buffer._charsWritten, 18);
|
||||
|
||||
// Check for fractional length args, junk length args, etc.
|
||||
// https://github.com/joyent/node/issues/1758
|
||||
Buffer(3.3).toString(); // throws bad argument error in commit 43cb4ec
|
||||
|
Loading…
x
Reference in New Issue
Block a user