2929#include < assert.h>
3030#include < string.h> // memcpy
3131
32- #ifdef __POSIX__
33- # include < sys/mman.h> // mmap
34- # include < unistd.h> // sysconf
35- # include < stdio.h> // perror
36- #endif
37-
3832#define MIN (a,b ) ((a) < (b) ? (a) : (b))
3933
4034#define BUFFER_CLASS_ID (0xBABE )
@@ -202,67 +196,6 @@ Buffer::~Buffer() {
202196}
203197
204198
205- #if defined(__POSIX__)
206-
207- static unsigned int num_pool_buffers;
208- static char * cached_pool_buffers[16 ];
209-
210-
211- static inline void free_buf_mem (char * buf, size_t len) {
212- if (len == Buffer::kPoolSize &&
213- num_pool_buffers < ARRAY_SIZE (cached_pool_buffers)) {
214- cached_pool_buffers[num_pool_buffers++] = buf;
215- return ;
216- }
217-
218- if (munmap (buf, len)) {
219- perror (" munmap" );
220- abort ();
221- }
222- }
223-
224-
225- static inline char * alloc_buf_mem (size_t len) {
226- size_t pagesize = sysconf (_SC_PAGESIZE);
227-
228- len = ROUND_UP (len, pagesize);
229- if (len == Buffer::kPoolSize && num_pool_buffers > 0 ) {
230- return cached_pool_buffers[--num_pool_buffers];
231- }
232-
233- int prot = PROT_READ | PROT_WRITE;
234- int flags = MAP_ANON | MAP_PRIVATE; // OS X doesn't know MAP_ANONYMOUS...
235- char * buf = static_cast <char *>(mmap (NULL , len, prot, flags, -1 , 0 ));
236-
237- if (buf == NULL ) {
238- TryCatch try_catch;
239- char errmsg[256 ];
240- snprintf (errmsg,
241- sizeof (errmsg),
242- " Out of memory, mmap(len=%lu) failed." ,
243- static_cast <unsigned long >(len));
244- ThrowError (errmsg);
245- FatalException (try_catch);
246- abort ();
247- }
248-
249- return buf;
250- }
251-
252- #else // !__POSIX__
253-
254- static inline void free_buf_mem (char * buf, size_t len) {
255- delete[] buf;
256- }
257-
258-
259- static inline char * alloc_buf_mem (size_t len) {
260- return new char [len];
261- }
262-
263- #endif // __POSIX__
264-
265-
266199// if replace doesn't have a callback, data must be copied
267200// const_cast in Buffer::New requires this
268201void Buffer::Replace (char *data, size_t length,
@@ -272,7 +205,7 @@ void Buffer::Replace(char *data, size_t length,
272205 if (callback_) {
273206 callback_ (data_, callback_hint_);
274207 } else if (length_) {
275- free_buf_mem (data_, length_) ;
208+ delete [] data_ ;
276209 V8::AdjustAmountOfExternalAllocatedMemory (
277210 -static_cast <intptr_t >(sizeof (Buffer) + length_));
278211 }
@@ -284,8 +217,9 @@ void Buffer::Replace(char *data, size_t length,
284217 if (callback_) {
285218 data_ = data;
286219 } else if (length_) {
287- data_ = alloc_buf_mem (length_);
288- if (data != NULL ) memcpy (data_, data, length_);
220+ data_ = new char [length_];
221+ if (data)
222+ memcpy (data_, data, length_);
289223 V8::AdjustAmountOfExternalAllocatedMemory (sizeof (Buffer) + length_);
290224 } else {
291225 data_ = NULL ;
@@ -896,8 +830,6 @@ void Buffer::Initialize(Handle<Object> target) {
896830 Buffer::MakeFastBuffer);
897831
898832 target->Set (String::NewSymbol (" SlowBuffer" ), constructor_template->GetFunction ());
899- target->Set (String::NewSymbol (" kPoolSize" ),
900- Integer::NewFromUnsigned (kPoolSize ));
901833
902834 HeapProfiler::DefineWrapperClass (BUFFER_CLASS_ID, WrapperInfo);
903835}
0 commit comments