Replace some unnecessary String.prototype.search usage

Most of the `String.prototype.search` call-sites found throughout the code-base is actually not necessary, since we usually only want a *boolean*, and those can be replaced with `RegExp.prototype.test` instead.
This commit is contained in:
Jonas Jenwald 2022-09-19 12:51:46 +02:00
parent dc6c3eacbc
commit bb75b36b77
2 changed files with 5 additions and 7 deletions

View File

@ -3866,8 +3866,7 @@ class PartialEvaluator {
// Simulating descriptor flags attribute
const fontNameWoStyle = baseFontName.split("-")[0];
return (
fontNameWoStyle in getSerifFonts() ||
fontNameWoStyle.search(/serif/gi) !== -1
fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle)
);
}

View File

@ -1119,17 +1119,16 @@ class Font {
}
}
this.bold = fontName.search(/bold/gi) !== -1;
this.italic =
fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
this.bold = /bold/gi.test(fontName);
this.italic = /oblique|italic/gi.test(fontName);
// Use 'name' instead of 'fontName' here because the original
// name ArialBlack for example will be replaced by Helvetica.
this.black = name.search(/Black/g) !== -1;
this.black = /Black/g.test(name);
// Use 'name' instead of 'fontName' here because the original
// name ArialNarrow for example will be replaced by Helvetica.
const isNarrow = name.search(/Narrow/g) !== -1;
const isNarrow = /Narrow/g.test(name);
// if at least one width is present, remeasure all chars when exists
this.remeasure =