Skip to content

Commit 45466f4

Browse files
authored
Merge pull request #330 from fwbrasil/opt-uri-token-decoding
optimize uri parsing to reduce StringBuilder allocations
2 parents 4df0e52 + 2aae990 commit 45466f4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/src/main/scala/sttp/model/UriInterpolator.scala

+10
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,16 @@ object UriInterpolator {
731731
case Singleton(ExpressionToken(s: Array[_])) =>
732732
b ++= s.flatMap(anyToStringOpt)
733733
doToSeq(tailTs)
734+
case valueTs if(valueTs.size == 1) =>
735+
// This case is equivalent to the next one but optimizes for the
736+
// frequent scenario where the sequence contains a single element.
737+
valueTs.get(0) match {
738+
case StringToken(s) => b += decode(s, decodePlusAsSpace)
739+
case ExpressionToken(e) => anyToStringOpt(e).foreach(b += _)
740+
case EqInQuery => b += "="
741+
case _ =>
742+
}
743+
doToSeq(tailTs)
734744
case valueTs =>
735745
val mbStr = valueTs mkStringOpt {
736746
case StringToken(s) => Some(decode(s, decodePlusAsSpace))

0 commit comments

Comments
 (0)