Skip to content

Commit

Permalink
fix: don't create regex object everytime
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 10, 2020
1 parent 733abf5 commit f6bd11e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src-commons-ui/float-pane/SnippetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class SnippetView extends React.Component<Props, State> {
}
}

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
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit f6bd11e

Please sign in to comment.