From 26ca5059d8c3e635ac237a9ca8a03152d98bd191 Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Wed, 27 Mar 2024 21:57:11 -0500 Subject: [PATCH] Fix slowness with larger templates Closes #69 and #71 Released 3.0.5 --- README.md | 2 +- mo | 28 +++++++++++++++++++--------- tests/help | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ab15e08..cf6bd81 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ Please note that this command is written in Bash and pulls data from either the Enhancements ------------ +------------ In addition to many of the features built-in to Mustache, `mo` includes a number of unique features that make it a bit more powerful. diff --git a/mo b/mo index 1ef1e5c..9a4707f 100755 --- a/mo +++ b/mo @@ -430,19 +430,29 @@ mo::indirectArray() { # # Returns nothing. mo::trimUnparsed() { - local moLast moR moN moT + local moLastLen moR moN moT - moLast="" + moLastLen=0 moR=$'\r' moN=$'\n' moT=$'\t' - while [[ "$MO_UNPARSED" != "$moLast" ]]; do - moLast=$MO_UNPARSED - MO_UNPARSED=${MO_UNPARSED# } - MO_UNPARSED=${MO_UNPARSED#"$moR"} - MO_UNPARSED=${MO_UNPARSED#"$moN"} - MO_UNPARSED=${MO_UNPARSED#"$moT"} + while [[ "${#MO_UNPARSED}" != "$moLastLen" ]]; do + moLastLen=${#MO_UNPARSED} + + # These conditions are necessary for a significant speed increase + while [[ "${MO_UNPARSED:0:1}" == " " ]]; do + MO_UNPARSED=${MO_UNPARSED# } + done + while [[ "${MO_UNPARSED:0:1}" == "$moR" ]]; do + MO_UNPARSED=${MO_UNPARSED#"$moR"} + done + while [[ "${MO_UNPARSED:0:1}" == "$moN" ]]; do + MO_UNPARSED=${MO_UNPARSED#"$moN"} + done + while [[ "${MO_UNPARSED:0:1}" == "$moT" ]]; do + MO_UNPARSED=${MO_UNPARSED#"$moT"} + done done } @@ -1950,7 +1960,7 @@ mo::tokenizeTagContentsSingleQuote() { # Save the original command's path for usage later MO_ORIGINAL_COMMAND="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)/${BASH_SOURCE[0]##*/}" -MO_VERSION="3.0.4" +MO_VERSION="3.0.5" # If sourced, load all functions. # If executed, perform the actions as expected. diff --git a/tests/help b/tests/help index 420b37a..1d4ba29 100755 --- a/tests/help +++ b/tests/help @@ -94,7 +94,7 @@ This is open source! Please feel free to contribute. https://github.com/tests-always-included/mo -MO_VERSION=3.0.4 +MO_VERSION=3.0.5 EOF }