22
22
#include " node.h"
23
23
#include " node_buffer.h"
24
24
#include " handle_wrap.h"
25
- #include " slab_allocator.h"
26
25
#include " stream_wrap.h"
27
26
#include " pipe_wrap.h"
28
27
#include " tcp_wrap.h"
33
32
#include < stdlib.h> // abort()
34
33
#include < limits.h> // INT_MAX
35
34
36
- #define SLAB_SIZE (1024 * 1024 )
37
-
38
35
39
36
namespace node {
40
37
@@ -49,6 +46,7 @@ using v8::Number;
49
46
using v8::Object;
50
47
using v8::Persistent;
51
48
using v8::String;
49
+ using v8::Uint32;
52
50
using v8::Value;
53
51
54
52
@@ -58,23 +56,13 @@ static Persistent<String> write_queue_size_sym;
58
56
static Persistent<String> onread_sym;
59
57
static Persistent<String> oncomplete_sym;
60
58
static Persistent<String> handle_sym;
61
- static SlabAllocator* slab_allocator;
62
59
static bool initialized;
63
60
64
61
65
- static void DeleteSlabAllocator (void *) {
66
- delete slab_allocator;
67
- slab_allocator = NULL ;
68
- }
69
-
70
-
71
62
void StreamWrap::Initialize (Handle<Object> target) {
72
63
if (initialized) return ;
73
64
initialized = true ;
74
65
75
- slab_allocator = new SlabAllocator (SLAB_SIZE);
76
- AtExit (DeleteSlabAllocator, NULL );
77
-
78
66
HandleScope scope (node_isolate);
79
67
80
68
HandleWrap::Initialize (target);
@@ -592,8 +580,7 @@ void StreamWrapCallbacks::AfterWrite(WriteWrap* w) {
592
580
593
581
uv_buf_t StreamWrapCallbacks::DoAlloc (uv_handle_t * handle,
594
582
size_t suggested_size) {
595
- char * buf = slab_allocator->Allocate (wrap_->object_ , suggested_size);
596
- return uv_buf_init (buf, suggested_size);
583
+ return uv_buf_init (new char [suggested_size], suggested_size);
597
584
}
598
585
599
586
@@ -604,26 +591,30 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
604
591
HandleScope scope (node_isolate);
605
592
606
593
if (nread < 0 ) {
607
- // If libuv reports an error or EOF it *may* give us a buffer back. In that
608
- // case, return the space to the slab.
609
594
if (buf.base != NULL )
610
- slab_allocator-> Shrink ( Self (), buf.base , 0 ) ;
595
+ delete[] buf.base ;
611
596
612
597
SetErrno (uv_last_error (uv_default_loop ()));
613
598
MakeCallback (Self (), onread_sym, 0 , NULL );
614
599
return ;
615
600
}
616
601
617
- Local<Object> slab = slab_allocator->Shrink (wrap_->object_ , buf.base , nread);
602
+ if (nread == 0 ) {
603
+ if (buf.base != NULL )
604
+ delete[] buf.base ;
605
+ return ;
606
+ }
607
+
608
+ // TODO(trevnorris): not kosher to use new/delete w/ realloc
609
+ buf.base = static_cast <char *>(realloc (buf.base , nread));
618
610
619
- if (nread == 0 ) return ;
620
611
assert (static_cast <size_t >(nread) <= buf.len );
621
612
622
613
int argc = 3 ;
623
614
Local<Value> argv[4 ] = {
624
- slab ,
625
- Integer::NewFromUnsigned (buf. base - Buffer::Data (slab) , node_isolate),
626
- Integer::NewFromUnsigned (nread, node_isolate)
615
+ Buffer::Use (buf. base , nread) ,
616
+ Uint32::New ( 0 , node_isolate),
617
+ Uint32::New (nread, node_isolate)
627
618
};
628
619
629
620
Local<Object> pending_obj;
0 commit comments