Skip to content

Commit

Permalink
Merge pull request #330 from fwbrasil/opt-uri-token-decoding
Browse files Browse the repository at this point in the history
optimize uri parsing to reduce StringBuilder allocations
  • Loading branch information
adamw authored Mar 5, 2024
2 parents 4df0e52 + 2aae990 commit 45466f4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/sttp/model/UriInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,16 @@ object UriInterpolator {
case Singleton(ExpressionToken(s: Array[_])) =>
b ++= s.flatMap(anyToStringOpt)
doToSeq(tailTs)
case valueTs if(valueTs.size == 1) =>
// This case is equivalent to the next one but optimizes for the
// frequent scenario where the sequence contains a single element.
valueTs.get(0) match {
case StringToken(s) => b += decode(s, decodePlusAsSpace)
case ExpressionToken(e) => anyToStringOpt(e).foreach(b += _)
case EqInQuery => b += "="
case _ =>
}
doToSeq(tailTs)
case valueTs =>
val mbStr = valueTs mkStringOpt {
case StringToken(s) => Some(decode(s, decodePlusAsSpace))
Expand Down

0 comments on commit 45466f4

Please # to comment.