From c6e1843ecb60e28353e08d6e0fce93b2b0759d12 Mon Sep 17 00:00:00 2001 From: hsfzxjy Date: Fri, 29 Sep 2023 12:20:31 +0800 Subject: [PATCH] Faster __vsc_escape_value --- .../terminal/browser/media/shellIntegration-bash.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh index 687b9ee025a..50ea1e39a52 100755 --- a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh +++ b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh @@ -95,9 +95,22 @@ __vsc_get_trap() { builtin printf '%s' "${terms[2]:-}" } +__vsc_escape_value_fast() { + builtin local LC_ALL=C out + out=${1//\\/\\\\} + out=${out//;/\\x3b} + builtin printf '%s\n' "${out}" +} + # The property (P) and command (E) codes embed values which require escaping. # Backslashes are doubled. Non-alphanumeric characters are converted to escaped hex. __vsc_escape_value() { + # If the input being too large, switch to the faster function + if [ "${#1}" -ge 2000 ]; then + __vsc_escape_value_fast "$1" + builtin return + fi + # Process text byte by byte, not by codepoint. builtin local LC_ALL=C str="${1}" i byte token out=''