From 3f606d8c75a45a2869527f70e1cd6e1397df3b0d Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 14 Feb 2020 16:45:53 -0500 Subject: [PATCH] remove some duplicated code --- lib/deduplicate.js | 11 ----------- lib/hk-util.js | 4 ++-- lib/metadata.js | 2 +- lib/once.js | 7 ------- 4 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 lib/deduplicate.js delete mode 100644 lib/once.js diff --git a/lib/deduplicate.js b/lib/deduplicate.js deleted file mode 100644 index 3ad62e6b0..000000000 --- a/lib/deduplicate.js +++ /dev/null @@ -1,11 +0,0 @@ -// remove duplicate elements in an array -module.exports = function (O) { - // make a copy of the original array - var A = O.slice(); - for (var i = 0; i < A.length; i++) { - for (var j = i + 1; j < A.length; j++) { - if (A[i] === A[j]) { A.splice(j--, 1); } - } - } - return A; -}; diff --git a/lib/hk-util.js b/lib/hk-util.js index 0a661c6c8..3221d50a2 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -3,7 +3,7 @@ var HK = module.exports; const nThen = require('nthen'); -const Once = require("./once"); +const Util = require("./common-util"); const Meta = require("./metadata"); const Nacl = require('tweetnacl/nacl-fast'); @@ -182,7 +182,7 @@ const computeIndex = function (Env, channelName, cb) { const ref = {}; - const CB = Once(cb); + const CB = Util.once(cb); const offsetByHash = {}; let size = 0; diff --git a/lib/metadata.js b/lib/metadata.js index 2b3a0b737..220327456 100644 --- a/lib/metadata.js +++ b/lib/metadata.js @@ -1,6 +1,6 @@ var Meta = module.exports; -var deduplicate = require("./deduplicate"); +var deduplicate = require("./common-util").deduplicateString; /* Metadata fields: diff --git a/lib/once.js b/lib/once.js deleted file mode 100644 index a851af259..000000000 --- a/lib/once.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function (f, g) { - return function () { - if (!f) { return; } - f.apply(this, Array.prototype.slice.call(arguments)); - f = g; - }; -};