minor performance tuning;
authorwenzelm
Fri, 28 Jun 2024 13:25:51 +0200
changeset 80445 00f5e829d8b4
parent 80444 2bbcfcfca0cd
child 80446 996b5eb7c89e
minor performance tuning;
src/Pure/General/symbol.scala
--- a/src/Pure/General/symbol.scala	Fri Jun 28 13:46:06 2024 +0200
+++ b/src/Pure/General/symbol.scala	Fri Jun 28 13:25:51 2024 +0200
@@ -266,19 +266,32 @@
     }
     def recode(text: String): String = {
       val n = text.length
-      val matcher = new Symbol.Matcher(text)
-      Library.string_builder(hint = n) { result =>
+      val relevant = {
         var i = 0
-        while (i < n) {
+        var found = false
+        while (i < n && !found) {
           val c = text(i)
-          if (min <= c && c <= max) {
-            val s = matcher.match_symbol(i)
-            result.append(table.getOrElse(s, s))
-            i += s.length
+          if (min <= c && c <= max) { found = true }
+          i += 1
+        }
+        found
+      }
+      if (relevant) {
+        val matcher = new Symbol.Matcher(text)
+        Library.string_builder(hint = n) { result =>
+          var i = 0
+          while (i < n) {
+            val c = text(i)
+            if (min <= c && c <= max) {
+              val s = matcher.match_symbol(i)
+              result.append(table.getOrElse(s, s))
+              i += s.length
+            }
+            else { result.append(c); i += 1 }
           }
-          else { result.append(c); i += 1 }
         }
       }
+      else text
     }
   }