Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean zio.http.codec.internal.AtomizedCodecs code #3212

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,36 @@ private[http] final case class AtomizedCodecs(

def makeInputsBuilder(): Mechanic.InputsBuilder = {
Atomized(
Array.ofDim(method.length),
Array.ofDim(status.length),
Array.ofDim(path.length),
Array.ofDim(query.length),
Array.ofDim(header.length),
Array.ofDim(content.length),
method = Array.ofDim(method.length),
path = Array.ofDim(path.length),
query = Array.ofDim(query.length),
header = Array.ofDim(header.length),
content = Array.ofDim(content.length),
status = Array.ofDim(status.length),
)
}

def optimize: AtomizedCodecs =
AtomizedCodecs(
method.materialize,
path.materialize,
query.materialize,
header.materialize,
content.materialize,
status.materialize,
method = method.materialize,
path = path.materialize,
query = query.materialize,
header = header.materialize,
content = content.materialize,
status = status.materialize,
)
}

private[http] object AtomizedCodecs {
val empty = AtomizedCodecs(Chunk.empty, Chunk.empty, Chunk.empty, Chunk.empty, Chunk.empty, Chunk.empty)
val empty: AtomizedCodecs =
AtomizedCodecs(
method = Chunk.empty,
path = Chunk.empty,
query = Chunk.empty,
header = Chunk.empty,
content = Chunk.empty,
status = Chunk.empty,
)

def flatten[R, A](in: HttpCodec[R, A]): AtomizedCodecs = {
val atoms = flattenedAtoms(in)
Expand All @@ -80,7 +88,7 @@ private[http] object AtomizedCodecs {
private def flattenedAtoms[R, A](in: HttpCodec[R, A]): Chunk[Atom[_, _]] =
in match {
case Combine(left, right, _) => flattenedAtoms(left) ++ flattenedAtoms(right)
case atom: Atom[_, _] => Chunk(atom)
case atom: Atom[_, _] => Chunk.single(atom)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chunk constructor does this anyway.

case map: TransformOrFail[_, _, _] => flattenedAtoms(map.api)
case Annotated(api, _) => flattenedAtoms(api)
case Empty => Chunk.empty
Expand Down
Loading