0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
Commit Graph

96 Commits

Author SHA1 Message Date
Łukasz Walukiewicz
2e28832660 buffer: fix offset checks
Fixed offset checks in Buffer.readInt32LE() and Buffer.readInt32BE()
functions.
2013-04-08 16:17:38 -07:00
Trevor Norris
d69a26b965 buffer: check logic simplification
Checks have been simplified and optimized for most-used cases.

Calling Buffer with another Buffer as the subject will now use the
SlowBuffer Copy method instead of the for loop.

No need to call for value coercion, just place the ternary inline.
2013-02-20 20:34:34 +01:00
Ben Noordhuis
3f7e88a852 buffer: accept negative indices in Buffer#slice()
A negative start or end parameter now indexes from the end of the
buffer. More in line with String#slice() and ArrayBuffer#slice().
2013-02-12 17:09:19 -08:00
Ben Noordhuis
cd42f56178 buffer: optimize Buffer.prototype.write(s, 'hex')
Move the implementation to C++ land. This is similar to commit 3f65916
but this time for the write() function and the Buffer(s, 'hex')
constructor.

Speeds up the benchmark below about 24x (2.6s vs 1:02m).

  var s = 'f';
  for (var i = 0; i < 26; ++i) s += s;  // 64 MB
  Buffer(s, 'hex');
2013-02-02 01:01:42 +01:00
Ben Noordhuis
3f65916fa9 buffer: optimize Buffer.prototype.toString('hex')
Move the implementation to C++ land. The old JS implementation used
string concatenation, was dog slow and consumed copious amounts of
memory for large buffers. Example:

  var buf = Buffer(0x1000000);  // 16 MB
  buf.toString('hex')           // Used 3+ GB of memory.

The new implementation operates in O(n) time and space.

Fixes #4700.
2013-02-01 23:07:17 +01:00
Trevor Norris
cbe3941db9 buffer: error and misc cleanup
Changed types of errors thrown to be more indicative of what the error
represents. Also removed a few unnecessary uses of the v8 fully
quantified typename.
2013-01-25 11:59:26 +01:00
Trevor Norris
49175e6ae2 buffer: clean up copy() asserts and tests
Argument checks were simplified by setting all undefined/NaN or out of
bounds values equal to their defaults.

Also copy() tests had a flaw that each buffer had the same bit pattern at
the same offset. So even if the copy failed, the bit-by-bit comparison
would have still been true. This was fixed by filling each buffer with a
unique value before copy operations.
2013-01-25 11:59:21 +01:00
Trevor Norris
16bbeccd40 buffer: slow buffer copy compatibility fix
Fix issue where SlowBuffers couldn't be passed as target to Buffer
copy().

Also included checks to see if Argument parameters are defined before
assigning their values. This offered ~3x's performance gain.
2013-01-25 11:58:51 +01:00
isaacs
3d7818fc42 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	src/node_version.h
	test/simple/test-buffer.js
2013-01-18 12:58:16 -08:00
Ben Noordhuis
498200b87c buffer: reject negative SlowBuffer offsets
Reject negative offsets in SlowBuffer::MakeFastBuffer(), it allows
the creation of buffers that point to arbitrary addresses.

Reported by Trevor Norris.
2013-01-17 01:22:11 +01:00
isaacs
b9ffc537e6 lint: Prefer double-quotes over single 2013-01-16 12:07:12 -08:00
Trevor Norris
7393740c7b buffer: improve read/write speed with assert
Improved assert check order of execution and added additional checks on
parameters to ensure no bad values make it through (e.g. negative offset
values).
2013-01-16 10:17:20 -08:00
Trevor Norris
22b84e6216 buffer: floating point read/write improvements
Improvements:
* floating point operations are approx 4x's faster
* Now write quiet NaN's
* all read/write on floating point now done in C, so no more need for
  lib/buffer_ieee754.js
* float values have more accurate min/max value checks
* add additional benchmarks for buffers read/write
* created benchmark/_bench_timer.js which is a simple library that
  can be included into any benchmark and provides an intelligent tracker
  for sync and async tests
* add benchmarks for DataView set methods
* add checks and tests to make sure offset is greater than 0
2013-01-16 10:17:20 -08:00
Bert Belder
a6b8f63660 buffer: zero-length buffers shouldn't be slab-backed 2013-01-14 22:20:03 +01:00
Bert Belder
e501ce4b21 buffer: zero-length buffers shouldn't be slab-backed 2013-01-14 22:19:22 +01:00
isaacs
6c5356bfe2 Revert "buffer: allocate memory with mmap()"
Also Revert "buffer: use MAP_ANON, fix OS X build"

This reverts commit ddb15603e7.
This reverts commit 2433ec8276.
2012-12-17 10:47:17 -08:00
Ben Noordhuis
2433ec8276 buffer: allocate memory with mmap()
Work around an issue with the glibc malloc() implementation where memory blocks
are never returned to the operating system when they are allocated with brk()
and have overlapping lifecycles.

Fixes #4283.
2012-12-16 10:19:09 +01:00
isaacs
77ed12fe7a Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/test/test-spawn.c
	deps/uv/uv.gyp
	src/cares_wrap.cc
	src/node.cc
	src/node_version.h
	test/simple/test-buffer.js
	tools/gyp/pylib/gyp/common.py
	tools/install.py
2012-12-13 16:57:58 -08:00
Trevor Norris
6772308883 buffer: Don't double-negate numeric buffer arg
Fix #4331

Using double negate forces values into 32bit space. Because of this
Math.ceil needs to be used. Since NaN comparisons are always false, use
that to our advantage to return 0 if it is.

Also added two tests to verify the changes.
2012-11-30 16:23:49 -08:00
Trevor Norris
13c5db9771 buffer: remove duplicate assertion tests
Many assertion tests are duplicated in buffer.js. These few could be easily
removed and still have all tests pass.
2012-11-10 02:11:04 +01:00
Ricky Ng-Adam
8bd4590a31 buffer: include encoding value in exception when invalid
Encoding failures can be somewhat confusing, especially when they are due to
control flow frameworks auto-filling parameters from the previous step output
values to functions (such as toString and write) that developers don't expect
to take an encoding parameter. By outputting the value as part of the message,
should make it easier to track down these sort of bugs.
2012-10-09 16:18:26 +02:00
Nathan Rajlich
a4ef01df07 buffer: implement Buffer.prototype.toJSON()
Returns an Array-representation of the Buffer.
Closes #3905.
2012-09-09 11:04:16 -07:00
koichik
7f404e3509 buffer: added support for writing NaN and Infinity
to writeDoubleBE(), writeDoubleLE(), writeFloatBE() and writeFloatLE().
Fixes #3934.
2012-09-02 21:01:43 +09:00
koichik
37f0eb8df3 Revert "buffer: added support for writing NaN and Infinity"
This reverts commit 6b9425fe37.
2012-09-02 20:59:50 +09:00
koichik
6b9425fe37 buffer: added support for writing NaN and Infinity
to writeDoubleBE(), writeDoubleLE(), writeFloatBE() and writeFloatLE().
Fixes #3934.
2012-09-02 00:27:17 +09:00
isaacs
05282588e0 Buffer.isEncoding(enc)
Re: #3918
2012-08-27 13:01:29 -07:00
Karl Skomski
57d53a47e8 Use parent SlowBuffer, if any, when Buffer is sliced
Closes #3416
Closes #3477
2012-06-21 01:46:04 +02:00
isaacs
d53cdc5378 Add Buffer.concat method
We write out this loop a lot of places throughout node.
It clearly needs to be an API method.
2012-06-11 15:51:23 -07:00
isaacs
a3753b496e Revert "Fix #3242 Actually deprecate 'binary' buffer encoding"
This reverts commit 5979f096d1.

Related:
- #3279
- #3278
2012-05-16 16:32:37 -07:00
isaacs
1665b4a2a3 lint 2012-05-15 18:04:43 -07:00
Nathan Rajlich
38542f76a9 buffer: make SlowBuffer inherit from Buffer
This frees us from manually having to copy over functions to SlowBuffer's
prototype (which has bitten us multiple times in the past).

As an added bonus, the `inspect()` function is now shared between Buffer
and SlowBuffer, removing some duplicate code.

Closes #3228.
2012-05-11 17:27:40 -07:00
isaacs
5979f096d1 Fix #3242 Actually deprecate 'binary' buffer encoding 2012-05-09 10:08:54 -07:00
koichik
ebbd4039bc buffer: add UTF-16LE encoding name. 2012-05-03 23:56:17 +09:00
Ben Noordhuis
285d8c6589 buffer: align fast buffers on 8 byte boundary
Prevents alignment issues when people create a typed array from a buffer.
Unaligned loads or stores are less efficent and (on some architectures) unsafe.
2012-03-29 01:31:31 +02:00
Phil Sung
cf2513e1aa buffer: don't pollute global namespace in buffer.readInt* 2011-12-22 23:26:43 +01:00
Ben Noordhuis
59a9a9b5b0 buffer: add .read*() and .write*() methods to SlowBuffer prototype
Fixes #2138.
2011-11-18 11:13:37 +01:00
Łukasz Walukiewicz
3b852d7fab buffer: fix minimum values for writeInt*() functions 2011-11-16 21:30:26 +01:00
Ben Noordhuis
d157131439 buffers: handle bad length argument in constructor
Coerce fractional, negative and non-numeric length arguments to numbers.
Fractional numbers are rounded up, negative numbers and non-numeric values
are set to zero.
2011-09-24 18:27:03 +02:00
koichik
526c54c979 buffer: write() should always set _charsWritten.
Fixes #1633.
2011-09-08 11:47:32 +09:00
Brian White
b7c23ac3f5 Incorporate endianness into buffer.read* function names instead of passing in a boolean flag 2011-08-12 15:49:57 +02:00
Ryan Dahl
2689d262ec Make buffer.INSPECT_MAX_BYTES public for mscdex 2011-08-08 19:04:34 -07:00
Ryan Dahl
7332c4022f Truncate Buffer.inspect at 50 bytes 2011-08-08 17:50:43 -07:00
Robert Mustacchi
0df08c6a0c Endian argument should be a boolean. Signed integers shouldn't run through checks for unsigned integers. Clean up jslint. Provide unchecked uint entry points. 2011-08-08 17:01:57 -07:00
Ryan Dahl
8527f00c3c Lazy load a few modules 2011-07-27 19:54:31 -07:00
koichik
50e147bd03 Add an optional length argument to Buffer.write()
Fixes #243.
Fixes #1361.
2011-07-24 02:01:02 +09:00
Devon Govett
562b469b35 More accurite error messages when writing beyond the length of a Buffer.
Fixes #1336.
2011-07-16 12:56:14 +09:00
Brian White
e505a1215c Add reading/writing of floats and doubles from/to buffers
Code for readIEEE754/writeIEEE754 is from jspack: http://code.google.com/p/jspack/
2011-05-15 18:39:07 -07:00
isaacs
205b9beb6b Merge branch 'v0.4'
Conflicts:
	lib/tls.js
	lib/url.js
	src/node_version.h
	test/simple/test-buffer.js
	test/simple/test-url.js
2011-05-07 20:38:32 -07:00
Konstantin Käfer
5e1b7cadb4 Add Buffer::fill method to do memset
Fixes #477.
2011-05-06 13:39:12 -07:00
Robert Mustacchi
9812e31e8b Add reading/writing of C integers to buffers 2011-05-01 14:02:33 -07:00