Permalink
Browse files

Other: Moved field comparer to util

  • Loading branch information...
dcodeIO committed Mar 20, 2017
1 parent fe93d43 commit d7493efe1a86a60f6cdcf7976523e69523d3f7a3
Showing with 11 additions and 12 deletions.
  1. +1 −12 src/encoder.js
  2. +10 −0 src/util.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(),
@@ -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;
};

0 comments on commit d7493ef

Please sign in to comment.