Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions kuri/src/commonMain/kotlin/org/dexpace/kuri/Uri.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class Uri internal constructor(
*
* @return the decoded, ordered, duplicate-preserving snapshot; empty when there is no query.
*/
public fun queryParameters(): QueryParameters = QueryParameters.parseOrEmpty(query)
public fun queryParameters(): QueryParameters = queryParameterSnapshot

/**
* The last non-empty decoded path segment — the "file name" — or `""` when the path has none.
Expand Down Expand Up @@ -213,7 +213,7 @@ public class Uri internal constructor(
*/
@get:JvmName("encodedPath")
public val encodedPath: String
get() = components.path.toUriPathString()
get() = encodedPathText

/**
* Returns a [Builder] pre-filled with this URI's components, for producing a modified copy.
Expand Down Expand Up @@ -524,6 +524,10 @@ public class Uri internal constructor(
private val decodedPath: String by lazy { computeDecodedPath() }
private val decodedPathSegments: List<String> by lazy { computeDecodedPathSegments() }

/** Encoded path and query snapshot, computed once each; both are immutable, mirroring [canonicalUri]. */
private val encodedPathText: String by lazy { components.path.toUriPathString() }
private val queryParameterSnapshot: QueryParameters by lazy { QueryParameters.parseOrEmpty(query) }

/**
* Percent-decodes the stored path — an opaque path whole, else each segment — backing [path].
*
Expand Down
13 changes: 10 additions & 3 deletions kuri/src/commonMain/kotlin/org/dexpace/kuri/Url.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public class Url internal constructor(
/** The decoded path segments in order (read-only); an opaque path yields its single decoded value. */
@get:JvmName("pathSegments")
public val pathSegments: List<String>
get() = decodedSegments(components.path) { PercentCodec.decode(it) }
get() = decodedPathSegments

/** The canonical encoded path string (e.g. `/a/b`, or the opaque path verbatim). */
@get:JvmName("encodedPath")
public val encodedPath: String
get() = serializeUrlPath(components)
get() = encodedPathText

/**
* The raw encoded query without its leading `?`, or `null` when no `?` was present.
Expand All @@ -157,7 +157,7 @@ public class Url internal constructor(
/** A decoded, immutable snapshot of the query's `name=value` pairs; never live. */
@get:JvmName("queryParameters")
public val queryParameters: QueryParameters
get() = QueryParameters.parseOrEmpty(components.query)
get() = queryParameterSnapshot

/**
* The raw encoded fragment without its leading `#`, or `null` when no `#` was present.
Expand Down Expand Up @@ -215,6 +215,13 @@ public class Url internal constructor(
/** Cached canonical serialization, computed once (permits caching an immutable value). */
private val canonicalHref: String by lazy { Serializer.serialize(components, ParseProfile.URL) }

/** Path/query projections, each computed once; every value is immutable, mirroring [canonicalHref]. */
private val decodedPathSegments: List<String> by lazy {
decodedSegments(components.path) { PercentCodec.decode(it) }
}
private val encodedPathText: String by lazy { serializeUrlPath(components) }
private val queryParameterSnapshot: QueryParameters by lazy { QueryParameters.parseOrEmpty(components.query) }

/**
* The canonical serialized URL; the basis of [toString], [equals], and [hashCode].
*
Expand Down
Loading