Skip to content

Commit

Permalink
optimize path encode method (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrutiVerma97 authored Feb 18, 2022
1 parent fea9f23 commit b57aa88
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions zio-http/src/main/scala/zhttp/http/PathModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ private[zhttp] trait PathModule { module =>
final def drop(n: Int): Path = Path(self.toList.drop(n))

final def encode: String = {
def loop(self: Path): String = {
@tailrec
def loop(self: Path, str: String): String = {
self match {
case Path.End => ""
case Path.Cons(name, path) => s"/${name}${loop(path)}"
case Path.End => str
case Path.Cons(name, path) => loop(path, s"$str/$name")
}
}
val result = loop(self)
if (result.isEmpty) "/" else result
val res = loop(self, "")
if (res.isEmpty) "/" else res
}

final def initial: Path = self match {
Expand Down

0 comments on commit b57aa88

Please sign in to comment.