slice: Refactor for improved performance.
This commit is contained in:
parent
10e4fdc083
commit
04bbe30a00
1 changed files with 10 additions and 2 deletions
12
lib/index.js
12
lib/index.js
|
@ -203,12 +203,20 @@ const Channel = function(bufferLength = 0) {
|
||||||
slice: (start, end = Infinity) => {
|
slice: (start, end = Infinity) => {
|
||||||
const output = Channel();
|
const output = Channel();
|
||||||
(async () => {
|
(async () => {
|
||||||
for (let index = 0; index < end; index++) {
|
for (let index = 0; index < start; index++) {
|
||||||
const value = await readOnly.shift();
|
const value = await readOnly.shift();
|
||||||
|
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
break;
|
break;
|
||||||
} else if (index >= start) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let index = start; index < end; index++) {
|
||||||
|
const value = await readOnly.shift();
|
||||||
|
|
||||||
|
if (value === undefined) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
await output.push(value);
|
await output.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue