Use a limit, in more places, when splitting strings
This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about. *Please note:* I cannot find an ESLint rule to enforce this automatically.
This commit is contained in:
parent
af4d2fa53c
commit
363dce6744
@ -47,7 +47,7 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
var scheme = url.slice(0, schemeIndex).toLowerCase();
|
var scheme = url.slice(0, schemeIndex).toLowerCase();
|
||||||
if (schemes.includes(scheme)) {
|
if (schemes.includes(scheme)) {
|
||||||
url = url.split("#")[0];
|
url = url.split("#", 1)[0];
|
||||||
if (url.charAt(schemeIndex) === ":") {
|
if (url.charAt(schemeIndex) === ":") {
|
||||||
url = encodeURIComponent(url);
|
url = encodeURIComponent(url);
|
||||||
}
|
}
|
||||||
|
@ -3955,7 +3955,7 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
isSerifFont(baseFontName) {
|
isSerifFont(baseFontName) {
|
||||||
// Simulating descriptor flags attribute
|
// Simulating descriptor flags attribute
|
||||||
const fontNameWoStyle = baseFontName.split("-")[0];
|
const fontNameWoStyle = baseFontName.split("-", 1)[0];
|
||||||
return (
|
return (
|
||||||
fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle)
|
fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle)
|
||||||
);
|
);
|
||||||
@ -4185,7 +4185,7 @@ class PartialEvaluator {
|
|||||||
const metrics = this.getBaseFontMetrics(baseFontName);
|
const metrics = this.getBaseFontMetrics(baseFontName);
|
||||||
|
|
||||||
// Simulating descriptor flags attribute
|
// Simulating descriptor flags attribute
|
||||||
const fontNameWoStyle = baseFontName.split("-")[0];
|
const fontNameWoStyle = baseFontName.split("-", 1)[0];
|
||||||
const flags =
|
const flags =
|
||||||
(this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
|
(this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
|
||||||
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
||||||
|
@ -968,7 +968,7 @@ class Font {
|
|||||||
// Fallback to checking the font name, in order to improve text-selection,
|
// Fallback to checking the font name, in order to improve text-selection,
|
||||||
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
|
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
|
||||||
if (!isSerifFont && !properties.isSimulatedFlags) {
|
if (!isSerifFont && !properties.isSimulatedFlags) {
|
||||||
const baseName = name.replaceAll(/[,_]/g, "-").split("-")[0],
|
const baseName = name.replaceAll(/[,_]/g, "-").split("-", 1)[0],
|
||||||
serifFonts = getSerifFonts();
|
serifFonts = getSerifFonts();
|
||||||
for (const namePart of baseName.split("+")) {
|
for (const namePart of baseName.split("+")) {
|
||||||
if (serifFonts[namePart]) {
|
if (serifFonts[namePart]) {
|
||||||
@ -1286,7 +1286,7 @@ class Font {
|
|||||||
}
|
}
|
||||||
|
|
||||||
amendFallbackToUnicode(properties);
|
amendFallbackToUnicode(properties);
|
||||||
this.loadedName = fontName.split("-")[0];
|
this.loadedName = fontName.split("-", 1)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAndRepair(name, font, properties) {
|
checkAndRepair(name, font, properties) {
|
||||||
|
@ -745,7 +745,7 @@ class Driver {
|
|||||||
if (!("message" in e)) {
|
if (!("message" in e)) {
|
||||||
return JSON.stringify(e);
|
return JSON.stringify(e);
|
||||||
}
|
}
|
||||||
return e.message + ("stack" in e ? " at " + e.stack.split("\n")[0] : "");
|
return e.message + ("stack" in e ? " at " + e.stack.split("\n", 1)[0] : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
_getLastPageNumber(task) {
|
_getLastPageNumber(task) {
|
||||||
|
@ -17,7 +17,7 @@ import { getPdfFilenameFromUrl } from "pdfjs-lib";
|
|||||||
|
|
||||||
async function docProperties(pdfDocument) {
|
async function docProperties(pdfDocument) {
|
||||||
const url = "",
|
const url = "",
|
||||||
baseUrl = url.split("#")[0];
|
baseUrl = url.split("#", 1)[0];
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let { info, metadata, contentDispositionFilename, contentLength } =
|
let { info, metadata, contentDispositionFilename, contentLength } =
|
||||||
await pdfDocument.getMetadata();
|
await pdfDocument.getMetadata();
|
||||||
|
@ -385,7 +385,7 @@ class PDFHistory {
|
|||||||
|
|
||||||
let newUrl;
|
let newUrl;
|
||||||
if (this._updateUrl && destination?.hash) {
|
if (this._updateUrl && destination?.hash) {
|
||||||
const baseUrl = document.location.href.split("#")[0];
|
const baseUrl = document.location.href.split("#", 1)[0];
|
||||||
// Prevent errors in Firefox.
|
// Prevent errors in Firefox.
|
||||||
if (!baseUrl.startsWith("file://")) {
|
if (!baseUrl.startsWith("file://")) {
|
||||||
newUrl = `${baseUrl}#${destination.hash}`;
|
newUrl = `${baseUrl}#${destination.hash}`;
|
||||||
|
Loading…
Reference in New Issue
Block a user