From 2e495dd5f5ec716c902d8dba7a722dd654ff36dd Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Mon, 29 Jul 2019 16:40:29 -0400 Subject: [PATCH] perf: save ~10ms on `player.src` call (#6141) Don't use a case-insensitive regex for getting the extname. Don't try to guess the type if we're provided with one. --- src/js/utils/filter-source.js | 8 +++++--- src/js/utils/url.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/utils/filter-source.js b/src/js/utils/filter-source.js index 050546c3f..7cfe02120 100644 --- a/src/js/utils/filter-source.js +++ b/src/js/utils/filter-source.js @@ -56,10 +56,12 @@ const filterSource = function(src) { * src Object with known type */ function fixSource(src) { - const mimetype = getMimetype(src.src); + if (!src.type) { + const mimetype = getMimetype(src.src); - if (!src.type && mimetype) { - src.type = mimetype; + if (mimetype) { + src.type = mimetype; + } } return src; diff --git a/src/js/utils/url.js b/src/js/utils/url.js index 176d32964..6d542027a 100644 --- a/src/js/utils/url.js +++ b/src/js/utils/url.js @@ -132,7 +132,7 @@ export const getAbsoluteURL = function(url) { */ export const getFileExtension = function(path) { if (typeof path === 'string') { - const splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/i; + const splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/; const pathParts = splitPathRe.exec(path); if (pathParts) {