From f6bd11e81ea42d8e12244027979f9d866d414694 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 9 Oct 2020 23:21:05 -0500 Subject: [PATCH] fix: don't create regex object everytime --- src-commons-ui/float-pane/SnippetView.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src-commons-ui/float-pane/SnippetView.tsx b/src-commons-ui/float-pane/SnippetView.tsx index fdb9efb4..76dab7cd 100644 --- a/src-commons-ui/float-pane/SnippetView.tsx +++ b/src-commons-ui/float-pane/SnippetView.tsx @@ -49,7 +49,9 @@ export class SnippetView extends React.Component { } } -const regExpLSPPrefix = /^\((method|property|parameter|alias)\)\W/ + +const regexPremeable = /^\s*<(\?|!)([a-zA-Z]+)?\s*/i +const regexLSPPrefix = /^\((method|property|parameter|alias)\)\W/ /** * converts a given code snippet into syntax formatted HTML @@ -81,8 +83,8 @@ export async function getSnippetHtml( snippets.forEach((snippet) => { const preElem = document.createElement("pre") const codeElem = document.createElement("code") - snippet = snippet.replace(/^\s*<(\?|!)([a-zA-Z]+)?\s*/i, "") // remove any preamble from the line - codeElem.innerText = snippet.replace(regExpLSPPrefix, "") + snippet = snippet.replace(regexPremeable, "") // remove any preamble from the line + codeElem.innerText = snippet.replace(regexLSPPrefix, "") // remove LSP prefix preElem.appendChild(codeElem) divElem.appendChild(preElem) })