Commit Graph

52 Commits

Author SHA1 Message Date
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
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
Ben Noordhuis
5664dd2fc1 src: use static_cast where appropriate
Use static_cast instead of reinterpret_cast when casting from void*
to another type.

This is mostly an aesthetic change but may help catch bugs when the
affected code is modified.
2013-01-05 00:16:23 +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
Pavel Lang
7ab4a77d6f buffer: update constructor prototype
Change Buffer::New(char*, size_t) to Buffer::New(const char*, size_t).
2012-09-13 16:31:04 +02:00
Ben Noordhuis
c8c638a841 buffer: change prototype of Data() and Length()
Make Buffer:Data() and Buffer::Length() accept a Value instead of an Object.
2012-09-11 18:33:30 +02:00
Ben Noordhuis
b82b4f2993 buffer: fix signedness compiler warnings 2012-03-30 14:52:38 +02:00
Ben Noordhuis
ff4a9d381d core: use proper #include directives 2012-03-10 00:14:14 +01:00
Ben Noordhuis
8c02f9b7c8 buffer: throw from constructor if length > kMaxLength
Throw, don't abort. `new Buffer(0x3fffffff + 1)` used to bring down the process
with the following error message:

  FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length
  exceeds max acceptable value

Fixes #2280.
2012-03-09 23:57:03 +01:00
Ben Noordhuis
74a8215a86 Revert support for isolates.
It was decided that the performance benefits that isolates offer (faster spin-up
times for worker processes, faster inter-worker communication, possibly a lower
memory footprint) are not actual bottlenecks for most people and do not outweigh
the potential stability issues and intrusive changes to the code base that
first-class support for isolates requires.

Hence, this commit backs out all isolates-related changes.

Good bye, isolates. We hardly knew ye.
2012-02-06 15:44:42 +01:00
Ryan Dahl
59055b227a Move node_buffer.cc globals to struct 2011-12-07 16:01:46 -08:00
Bert Belder
3e696d189c Windows: make Buffer and ObjectWrap available to compiled extensions
Closes GH-2036
2011-11-17 00:54:42 +01:00
Bert Belder
189dd8f803 Fix line endings and trailing whitespace 2011-11-04 16:24:34 +01:00
Ryan Dahl
5fd9adccdb Remove confusing comment in node_buffer.h 2011-06-14 13:18:32 +02:00
Konstantin Käfer
5e1b7cadb4 Add Buffer::fill method to do memset
Fixes #477.
2011-05-06 13:39:12 -07:00
Ryan Dahl
55048cdf79 Update copyright headers 2011-03-14 17:37:05 -07:00
Ben Noordhuis
594642b31d Buffer::Length(Buffer*) should not invoke itself recursively.
Closes GH-759.
2011-03-10 14:06:01 -08:00
Konstantin Käfer
9e101f2b01 UCS-2 support
Closes GH-644.
2011-02-07 13:35:06 -08:00
Ryan Dahl
468042fc84 Add C++ Buffer migration tips 2011-01-04 17:23:48 -08:00
Ryan Dahl
2320497992 Revert "Merge branch 'writev'"
This reverts commit cd9515efd9, reversing
changes made to df46c8e698.

Too slow. Needs more work.
2010-11-20 20:55:15 -08:00
Ryan Dahl
56074d1056 Inline Buffer::Length and Buffer::Data 2010-11-20 00:04:22 -08:00
Ryan Dahl
3884b4185a Small clean ups 2010-11-18 16:47:38 -08:00
Ryan Dahl
d74c506044 Support encoding 2010-11-18 16:47:37 -08:00
Ryan Dahl
41c1563584 Remove old buffer api 2010-11-01 14:59:30 -07:00
Ryan Dahl
dcc4fffe4d Add C++ API for constructing fast buffer from string 2010-10-26 13:43:58 -07:00
Stéphan Kochen
dd52737476 Provide a C++ Buffer constructor for external storage.
In order to do this, buffer data management was moved out of the
JS entry-point New, and into Replace.

Secondly, the constructor makes an immediate call to Replace, and
in order for ArrayData calls to work, wrapping must already be set
up. Now, the constructor takes the wrappee as a parameter.
2010-10-22 16:52:14 -07:00
Stéphan Kochen
d9b08d66d6 Remove old interface remains from Buffer.
These were all lacking implementation, so deprecating wouldn't help.
2010-10-22 13:32:31 -07:00
Ryan Dahl
0cf03ab800 Add char* constructor for Buffer 2010-10-10 19:08:51 -07:00
Ryan Dahl
b5359e40be Warnings for new C++ buffer API 2010-10-09 12:15:16 -07:00
Ryan Dahl
5bc4efe820 Remove blobs, simplify SlowBuffer
Implement SlowBuffer.prototype.slice in js
2010-09-09 11:03:51 -07:00
Ryan Dahl
1cf538a60a Work to get C++ fast buffers. incomplete 2010-09-09 11:03:48 -07:00
Ryan Dahl
565d862f3c Fix buffer binding 2010-09-09 11:03:48 -07:00
Tim-Smart
746d487da8 FastBuffer implementation. API needs migration 2010-09-09 11:03:47 -07:00
Ryan Dahl
488aff085b Improve appendix markdown 2010-08-21 01:24:14 -07:00
Ryan Dahl
2c1ca4078d Implement buffer.write for base64
There might be an off-by-one on the returned value.
2010-07-23 16:36:52 -07:00
Ryan Dahl
528015e0d8 Implement buffer.toString('base64') 2010-07-23 13:52:44 -07:00
Ryan Dahl
3768aaaea4 Create a public Buffer constructor for use in addons. 2010-05-24 13:26:18 -07:00
Ryan Dahl
44ad6a7db2 Make buffer's c++ constructor public 2010-05-20 09:44:10 -07:00
Ryan Dahl
85487c82d0 Blob struct should not contain actual data
This is to allow eventual realloc without messing up the data_ references in
all the slices.
2010-04-04 21:37:08 -07:00
Ryan Dahl
b72ffc0e07 Add buffer.copy 2010-04-04 18:59:40 -07:00
Ryan Dahl
ac684f3583 Add legacy 'binary' encoding/decoding methods to Buffer 2010-03-19 20:33:09 -07:00
Ryan Dahl
3a993d8897 Buffer.utf8ByteLength -> Buffer.byteLength 2010-03-19 12:02:59 -07:00
Ryan Dahl
1660db6b87 Inline Buffer::HasInstance 2010-02-02 19:35:06 -08:00
Ryan Dahl
4f56d8ae24 Rename Buffer.utf8Length to Buffer.utf8ByteLength 2010-02-01 13:10:37 -08:00
Ryan Dahl
785531691b Add buffer.unpack 2010-01-29 09:57:47 -08:00
Ryan Dahl
bf803f478b Reimplment Buffers 2010-01-27 15:40:09 -08:00
Ryan Dahl
741e3fa91b HTTP works somewhat on net2 now
However it's not working very well: Hitting a 'hello world' server with many
requests (ab -t 60 -c 10) will cause it to crash with the following error.

  Obtained 3 stack frames.

  ./node(_Z11print_tracev+0x1c) [0x80d1b3c]
  ./node(_ZN4node6Parser7ExecuteERKN2v89ArgumentsE+0x69) [0x80d3759]
  ./node [0x811f44b]
  TypeError: Already parsing a buffer
      at Socket.<anonymous> (/home/ryan/projects/node/lib/http2.js:393:20)
      at IOWatcher.callback (/home/ryan/projects/node/lib/net.js:81:12)
      at node.js:985:9
      at node.js:989:1
2010-01-25 17:55:08 -08:00
Ryan Dahl
bffa18befc Expose buffer_root() 2010-01-24 14:06:07 -08:00