forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
SlowBuffer = require('buffer').SlowBuffer; | ||
|
||
|
||
for (var i = 0; i < 9e7; i++) { | ||
b = new Buffer(10); | ||
for (var i = 0; i < 1e6; i++) { | ||
b = new SlowBuffer(10); | ||
b[1] = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var SlowBuffer = require('buffer').SlowBuffer; | ||
var POOLSIZE = 8*1024; | ||
var pool; | ||
|
||
function allocPool () { | ||
pool = new SlowBuffer(POOLSIZE); | ||
pool.used = 0; | ||
} | ||
|
||
function FastBuffer (length) { | ||
this.length = length; | ||
|
||
if (length > POOLSIZE) { | ||
// Big buffer, just alloc one. | ||
this.parent = new Buffer(length); | ||
this.offset = 0; | ||
} else { | ||
// Small buffer. | ||
if (!pool || pool.length - pool.used < length) allocPool(); | ||
this.parent = pool; | ||
this.offset = pool.used; | ||
pool.used += length; | ||
} | ||
|
||
// HERE HERE HERE | ||
SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length); | ||
} | ||
|
||
exports.FastBuffer = FastBuffer; | ||
|
||
FastBuffer.prototype.get = function (i) { | ||
if (i < 0 || i >= this.length) throw new Error("oob"); | ||
return this.parent[this.offset + i]; | ||
}; | ||
|
||
FastBuffer.prototype.set = function (i, v) { | ||
if (i < 0 || i >= this.length) throw new Error("oob"); | ||
return this.parent[this.offset + i] = v; | ||
}; | ||
|
||
// TODO define slice, toString, write, etc. | ||
// slice should not use c++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
FastBuffer = require('./fast_buffer2').FastBuffer; | ||
for (var i = 0; i < 1e6; i++) { | ||
b = new FastBuffer(10); | ||
b[1] = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
for (var i = 0; i < 1e6; i++) { | ||
b = new Buffer(10); | ||
b[1] = 2; | ||
} |