Skip to content

Commit

Permalink
lib,test: deprecate _linklist
Browse files Browse the repository at this point in the history
Deprecate _linklist and add test to confirm internal linklist and
public _linklist are the same.

PR-URL: #3078
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
Trott committed Oct 9, 2015
1 parent 01908d0 commit 47befff
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 60 deletions.
57 changes: 3 additions & 54 deletions lib/_linklist.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
'use strict';

function init(list) {
list._idleNext = list;
list._idlePrev = list;
}
exports.init = init;
const msg = require('internal/util').printDeprecationMessage;


// show the most idle item
function peek(list) {
if (list._idlePrev == list) return null;
return list._idlePrev;
}
exports.peek = peek;


// remove the most idle item from the list
function shift(list) {
var first = list._idlePrev;
remove(first);
return first;
}
exports.shift = shift;


// remove a item from its list
function remove(item) {
if (item._idleNext) {
item._idleNext._idlePrev = item._idlePrev;
}

if (item._idlePrev) {
item._idlePrev._idleNext = item._idleNext;
}

item._idleNext = null;
item._idlePrev = null;
}
exports.remove = remove;


// remove a item from its list and place at the end.
function append(list, item) {
remove(item);
item._idleNext = list._idleNext;
list._idleNext._idlePrev = item;
item._idlePrev = list;
list._idleNext = item;
}
exports.append = append;


function isEmpty(list) {
return list._idleNext === list;
}
exports.isEmpty = isEmpty;
module.exports = require('internal/linkedlist');
msg('_linklist module is deprecated. Please use a userland alternative.');
57 changes: 57 additions & 0 deletions lib/internal/linkedlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

function init(list) {
list._idleNext = list;
list._idlePrev = list;
}
exports.init = init;


// show the most idle item
function peek(list) {
if (list._idlePrev == list) return null;
return list._idlePrev;
}
exports.peek = peek;


// remove the most idle item from the list
function shift(list) {
var first = list._idlePrev;
remove(first);
return first;
}
exports.shift = shift;


// remove a item from its list
function remove(item) {
if (item._idleNext) {
item._idleNext._idlePrev = item._idlePrev;
}

if (item._idlePrev) {
item._idlePrev._idleNext = item._idleNext;
}

item._idleNext = null;
item._idlePrev = null;
}
exports.remove = remove;


// remove a item from its list and place at the end.
function append(list, item) {
remove(item);
item._idleNext = list._idleNext;
list._idleNext._idlePrev = item;
item._idlePrev = list;
list._idleNext = item;
}
exports.append = append;


function isEmpty(list) {
return list._idleNext === list;
}
exports.isEmpty = isEmpty;
2 changes: 1 addition & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Timer = process.binding('timer_wrap').Timer;
const L = require('_linklist');
const L = require('internal/linkedlist');
const assert = require('assert').ok;
const util = require('util');
const debug = util.debuglog('timer');
Expand Down
5 changes: 3 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'src/node.js',
'lib/_debug_agent.js',
'lib/_debugger.js',
'lib/_linklist.js',
'lib/assert.js',
'lib/buffer.js',
'lib/child_process.js',
Expand All @@ -39,6 +38,7 @@
'lib/_http_outgoing.js',
'lib/_http_server.js',
'lib/https.js',
'lib/_linklist.js',
'lib/module.js',
'lib/net.js',
'lib/os.js',
Expand Down Expand Up @@ -70,9 +70,10 @@
'lib/zlib.js',
'lib/internal/child_process.js',
'lib/internal/freelist.js',
'lib/internal/linkedlist.js',
'lib/internal/module.js',
'lib/internal/socket_list.js',
'lib/internal/repl.js',
'lib/internal/socket_list.js',
'lib/internal/util.js',
'lib/internal/streams/lazy_transform.js',
],
Expand Down
11 changes: 8 additions & 3 deletions test/parallel/test-timers-linked-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var L = require('_linklist');

// Flags: --expose-internals

const common = require('../common');
const assert = require('assert');
const L = require('_linklist');
const internalL = require('internal/linkedlist');

assert.strictEqual(L, internalL);

var list = { name: 'list' };
var A = { name: 'A' };
Expand Down

0 comments on commit 47befff

Please sign in to comment.