/*
 * This file is part of Placer, licensed under the MIT License (MIT).
 *
 * Copyright (c) Epic Planet Minecraft Server <https://epicpla.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package net.epicpla.placer;

import java.util.HashMap;
import java.util.Map;

public class Main {

    public static Map<String, String> placeholder = new HashMap<>();

    static {
        placeholder.put("50", "aa");
        placeholder.put("ab", "bb");
    }

    public static void main(final String[] args) {
        StringBuilder passedStringBuilder = new StringBuilder("");
        for (int i = 0; i <= 100; i++) {
            if (i == 50) {
                passedStringBuilder.append("<<").append(i).append(">asdf>");
            }
            passedStringBuilder.append("<").append(i).append(">");
        }

        String passedString = passedStringBuilder.toString();
        System.out.println(passedStringBuilder);

        long start = System.currentTimeMillis();
        for (int tt = 0; tt < 100000; tt ++) {
            StringBuilder builder = new StringBuilder(passedString);
            int lastHolderStart = 0;
            int startSearchFrom = -1;
            for (int i = builder.length() - 1; i >= 0; i --) {
                char ch = builder.charAt(i);
                if (ch == '>') {
                    lastHolderStart = i;
                } else if (ch == '<') {
                    if (lastHolderStart == -1) {
                        lastHolderStart = getLastHolderStart(startSearchFrom, builder);
                    }
                    String place = builder.substring(i + 1, lastHolderStart);
                    if(placeholder.containsKey(place)) {
                        String replaced = placeholder.get(place);
                        builder.replace(i, lastHolderStart + 1, replaced);

                        startSearchFrom = i + replaced.length();
                        lastHolderStart = -1;
                    } else {
                        startSearchFrom = lastHolderStart + 1;
                        lastHolderStart = -1;
                    }
                }

            }
            String result = builder.toString();
            if (tt == 99999) System.out.println(result);
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    public static int getLastHolderStart(int searchFrom, StringBuilder builder) {
        int temp = builder.length();
        for (int i = searchFrom; i < temp ; i ++) {
            if (builder.charAt(i) == '>') return i;
        }

        return -1;
    }
}
@@ -2039,32 +2039,265 @@
 0; tt ++) %7B%0A    
+        String result = parse(passedString);%0A            if (tt == 0) System.out.println(result);%0A        %7D%0A        System.out.println(System.currentTimeMillis() - start);%0A    %7D%0A%0A    public static String parse(String passedString) %7B%0A
         StringBu
@@ -2349,28 +2349,24 @@
 g);%0A        
-    
 int lastHold
@@ -2379,15 +2379,12 @@
 t = 
-0;%0A    
+-1;%0A
     
@@ -2409,28 +2409,24 @@
 hFrom = -1;%0A
-    
         for 
@@ -2484,20 +2484,16 @@
         
- 
-   
 char ch 
@@ -2529,28 +2529,47 @@
     
-    if (ch ==
+switch (ch) %7B%0A                case
  '%3E'
-) %7B
+:
 %0A   
@@ -2626,31 +2626,44 @@
     
-%7D else if (ch ==
+    break;%0A                case
  '%3C'
-) %7B
+:
 %0A   
@@ -3386,201 +3386,76 @@
     
-%7D%0A%0A            %7D%0A            String result = builder.toString();%0A            if (tt == 99999) System.out.println(result);%0A        %7D%0A        System.out.println(System.currentTimeMillis() - start
+    break;%0A            %7D%0A%0A        %7D%0A        return builder.toString(
 );%0A 

FIx Last Commit