diff --git a/src/org/rascalmpl/interpreter/TraversalEvaluator.java b/src/org/rascalmpl/interpreter/TraversalEvaluator.java index 505432e64d3..612699e119e 100644 --- a/src/org/rascalmpl/interpreter/TraversalEvaluator.java +++ b/src/org/rascalmpl/interpreter/TraversalEvaluator.java @@ -45,7 +45,6 @@ import org.rascalmpl.interpreter.utils.Cases.CaseBlock; import org.rascalmpl.types.RascalType; import org.rascalmpl.interpreter.utils.Names; -import org.rascalmpl.values.IRascalValueFactory; import org.rascalmpl.values.RascalValueFactory; import org.rascalmpl.values.parsetrees.ITree; import org.rascalmpl.values.parsetrees.TreeAdapter; @@ -690,11 +689,11 @@ public IValue traverseTop(IValue subject, CaseBlockList casesOrRules, TraverseRe * Performance issue: we create a lot of garbage by producing all these substrings. */ public IValue traverseString(IValue subject, CaseBlockList casesOrRules, TraverseResult tr){ - IString subjectString = (IString) subject; + String subjectString = ((IString) subject).getValue(); int len = subjectString.length(); int subjectCursor = 0; int subjectCursorForResult = 0; - IString replacementString = null; + StringBuffer replacementString = null; boolean hasMatched = false; boolean hasChanged = false; @@ -704,7 +703,7 @@ public IValue traverseString(IValue subject, CaseBlockList casesOrRules, Travers while (subjectCursor < len) { try { - IString substring = subjectString.substring(subjectCursor, len); + IString substring = eval.getValueFactory().string(subjectString.substring(subjectCursor, len)); IValue subresult = substring; tr.matched = false; tr.changed = false; @@ -742,16 +741,16 @@ else if (lastPattern instanceof LiteralPattern || lastPattern instanceof TypedVa // Create replacementString when this is the first replacement if (replacementString == null) { - replacementString = IRascalValueFactory.getInstance().string(""); + replacementString = new StringBuffer(); } // Copy string before the match to the replacement string for (; subjectCursorForResult < subjectCursor + start; subjectCursorForResult++){ - replacementString = replacementString.concat(IRascalValueFactory.getInstance().string(subjectString.charAt(subjectCursorForResult))); + replacementString.append(subjectString.charAt(subjectCursorForResult)); } subjectCursorForResult = subjectCursor + end; // Copy replacement into replacement string - replacementString = replacementString.concat((IString) repl); + replacementString.append(((IString)repl).getValue()); tr.matched = true; tr.changed = true; @@ -771,9 +770,9 @@ else if (lastPattern instanceof LiteralPattern || lastPattern instanceof TypedVa // Copy remaining characters of subject string into replacement string for (; subjectCursorForResult < len; subjectCursorForResult++){ - replacementString = replacementString.concat(IRascalValueFactory.getInstance().string(subjectString.charAt(subjectCursorForResult))); + replacementString.append(subjectString.charAt(subjectCursorForResult)); } - return replacementString; + return eval.getValueFactory().string(replacementString.toString()); } } diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/Strings1.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/Strings1.rsc index 652b897c330..c50e0bd14b1 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/Strings1.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/Strings1.rsc @@ -265,21 +265,21 @@ test bool tstSqueezeCase4() = squeeze("aabbcc", "a-c") == "abc"; test bool tstSqueezeCase5() = squeeze("aaabc", "a-c") == "abc"; // second squeeze -test bool tstSqueeze21(str S) = // !:= squeeze(S, #[a-zA-Z]); -test bool tstSqueeze22(str S) = squeeze(S, #[]) == S; -test bool tstSqueeze23(str S) { +test bool tstSqueeze1(str S) = // !:= squeeze(S, #[a-zA-Z]); +test bool tstSqueeze2(str S) = squeeze(S, #[]) == S; +test bool tstSqueeze3(str S) { if (// := S) { return // := squeeze(S, #[0-9]); } return true; } -test bool tstSqueeze2Unicode() = squeeze("Hi ๐Ÿ๐ŸWorld", #[๐Ÿ]) == "Hi ๐ŸWorld"; -test bool tstSqueeze2Case1() = squeeze("abc", #[a-c]) == "abc"; -test bool tstSqueeze2Case2() = squeeze("aabc", #[a-c]) == "abc"; -test bool tstSqueeze2Case3() = squeeze("aabcc", #[a-c]) == "abc"; -test bool tstSqueeze2Case4() = squeeze("aabbcc", #[a-c]) == "abc"; -test bool tstSqueeze2Case5() = squeeze("aaabc", #[a-c]) == "abc"; +test bool tstSqueezeUnicode() = squeeze("Hi ๐Ÿ๐ŸWorld", #[๐Ÿ]) == "Hi ๐ŸWorld"; +test bool tstSqueezeCase1() = squeeze("abc", #[a-c]) == "abc"; +test bool tstSqueezeCase2() = squeeze("aabc", #[a-c]) == "abc"; +test bool tstSqueezeCase3() = squeeze("aabcc", #[a-c]) == "abc"; +test bool tstSqueezeCase4() = squeeze("aabbcc", #[a-c]) == "abc"; +test bool tstSqueezeCase5() = squeeze("aaabc", #[a-c]) == "abc"; test bool tstStartsWith(str S1, str S2) = startsWith(S1+S2, S1);