Skip to content

Commit d7493ef

Browse files
committed
Other: Moved field comparer to util
1 parent fe93d43 commit d7493ef

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/encoder.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ function genTypePartial(gen, field, fieldIndex, ref) {
2222
: gen("types[%d].encode(%s,w.uint32(%d).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
2323
}
2424

25-
/**
26-
* Compares reflected fields by id.
27-
* @param {Field} a First field
28-
* @param {Field} b Second field
29-
* @returns {number} Comparison value
30-
* @ignore
31-
*/
32-
function compareFieldsById(a, b) {
33-
return a.id - b.id;
34-
}
35-
3625
/**
3726
* Generates an encoder specific to the specified message type.
3827
* @param {Type} mtype Message type
@@ -51,7 +40,7 @@ function encoder(mtype) {
5140
var fields = /* initializes */ mtype.fieldsArray;
5241
/* istanbul ignore else */
5342
if (encoder.compat)
54-
fields = fields.slice().sort(compareFieldsById);
43+
fields = fields.slice().sort(util.compareFieldsById);
5544

5645
for (var i = 0; i < fields.length; ++i) {
5746
var field = fields[i].resolve(),

src/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ util.safeProp = function safeProp(prop) {
4949
util.ucFirst = function ucFirst(str) {
5050
return str.charAt(0).toUpperCase() + str.substring(1);
5151
};
52+
53+
/**
54+
* Compares reflected fields by id.
55+
* @param {Field} a First field
56+
* @param {Field} b Second field
57+
* @returns {number} Comparison value
58+
*/
59+
util.compareFieldsById = function compareFieldsById(a, b) {
60+
return a.id - b.id;
61+
};

0 commit comments

Comments
 (0)