Skip to content

Commit b5b3056

Browse files
committed
remove regexp for performance
1 parent ad1a756 commit b5b3056

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/v1/decoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ proto.readObject = function (withType) {
423423
debug('read object finish');
424424

425425
// java.lang.NoClassDefFoundError
426-
if (/Exception$/.test(type) || /^java\.lang\.\w+Error$/.test(type)) {
426+
if (type.endsWith('Exception') || (type.startsWith('java.lang.') && type.endsWith('Error'))) {
427427
result.$ = new JavaExceptionError(result, withType);
428428
}
429429

lib/v2/decoder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ proto.readObject = function (withType) {
571571
} else {
572572
this.throwError('readObject', code);
573573
}
574-
574+
575575
var cls = this.classes[ref];
576576
debug('readObject %s, ref: %s', cls.name, ref);
577577

@@ -590,7 +590,7 @@ proto.readObject = function (withType) {
590590
}
591591
}
592592

593-
if (/Exception$/.test(cls.name)) {
593+
if (cls.name.endsWith('Exception')) {
594594
result.$ = new JavaExceptionError(result, withType);
595595
}
596596

@@ -759,7 +759,7 @@ utils.addByteCodes(BYTE_CODES, [
759759
* v2.0
760760
* ```
761761
* map ::= M(x4d) [type] (value value)* Z
762-
*
762+
*
763763
* @see http://hessian.caucho.com/doc/hessian-serialization.html##map
764764
* ```
765765
* Represents serialized maps and can represent objects.
@@ -801,7 +801,7 @@ proto.readMap = function (withType) {
801801
this._addRef(result);
802802
this._readMap(result.$, withType);
803803

804-
if (/Exception$/.test(type)) {
804+
if (type.endsWith('Exception')) {
805805
result.$ = new JavaExceptionError(result);
806806
}
807807

0 commit comments

Comments
 (0)