Skip to content

Commit

Permalink
Use hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Feb 20, 2024
1 parent d0b5960 commit f5a8ee1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/commonMain/kotlin/measure-consumer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import kotlin.time.*
val <O : Appendable> TimedValue<O>.out: O
get() = value

private class TimeMeasureConsumer<R>(val downstream: TagConsumer<R>, val timeSource: TimeSource) : TagConsumer<TimedValue<R>> {
private val start = timeSource.markNow()

private class TimeMeasureConsumer<R>(val downstream: TagConsumer<R>, val start: TimeMark) : TagConsumer<TimedValue<R>> {
override fun onTagStart(tag: Tag) {
downstream.onTagStart(tag)
}
Expand Down Expand Up @@ -45,4 +43,4 @@ private class TimeMeasureConsumer<R>(val downstream: TagConsumer<R>, val timeSou
override fun finalize(): TimedValue<R> = TimedValue(downstream.finalize(), start.elapsedNow())
}

fun <R> TagConsumer<R>.measureTime(timeSource: TimeSource = TimeSource.Monotonic): TagConsumer<TimedValue<R>> = TimeMeasureConsumer(this, timeSource)
fun <R> TagConsumer<R>.measureTime(timeSource: TimeSource = TimeSource.Monotonic): TagConsumer<TimedValue<R>> = TimeMeasureConsumer(this, timeSource.markNow())
4 changes: 1 addition & 3 deletions src/commonMain/kotlin/trace-consumer.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package kotlinx.html.consumers

import kotlinx.html.*
import kotlin.random.*

class TraceConsumer<R>(val downstream: TagConsumer<R>, val println: (String) -> Unit) : TagConsumer<R> by downstream {
private val random = Random.nextInt()
private val id = "ID-$random"
private val id = "ID-${hashCode()}"
private val path = ArrayList<String>(1024)

override fun onTagStart(tag: Tag) {
Expand Down

0 comments on commit f5a8ee1

Please sign in to comment.