From d7493efe1a86a60f6cdcf7976523e69523d3f7a3 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Mon, 20 Mar 2017 23:20:13 +0100 Subject: [PATCH] Other: Moved field comparer to util --- src/encoder.js | 13 +------------ src/util.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/encoder.js b/src/encoder.js index 898a43b8c..cf6c9a916 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -22,17 +22,6 @@ function genTypePartial(gen, field, fieldIndex, ref) { : gen("types[%d].encode(%s,w.uint32(%d).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0); } -/** - * Compares reflected fields by id. - * @param {Field} a First field - * @param {Field} b Second field - * @returns {number} Comparison value - * @ignore - */ -function compareFieldsById(a, b) { - return a.id - b.id; -} - /** * Generates an encoder specific to the specified message type. * @param {Type} mtype Message type @@ -51,7 +40,7 @@ function encoder(mtype) { var fields = /* initializes */ mtype.fieldsArray; /* istanbul ignore else */ if (encoder.compat) - fields = fields.slice().sort(compareFieldsById); + fields = fields.slice().sort(util.compareFieldsById); for (var i = 0; i < fields.length; ++i) { var field = fields[i].resolve(), diff --git a/src/util.js b/src/util.js index 3a255da6f..9e3557e3c 100644 --- a/src/util.js +++ b/src/util.js @@ -49,3 +49,13 @@ util.safeProp = function safeProp(prop) { util.ucFirst = function ucFirst(str) { return str.charAt(0).toUpperCase() + str.substring(1); }; + +/** + * Compares reflected fields by id. + * @param {Field} a First field + * @param {Field} b Second field + * @returns {number} Comparison value + */ +util.compareFieldsById = function compareFieldsById(a, b) { + return a.id - b.id; +};