Skip to content

Commit

Permalink
Other: Moved field comparer to util
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 20, 2017
1 parent fe93d43 commit d7493ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
13 changes: 1 addition & 12 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.