Skip to content

Commit

Permalink
feature(instrumentation): optimize parsing memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Apr 23, 2020
1 parent cb61f29 commit 11b3075
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ class InstrumentationResponseTransformer : ResponseTransformer<List<TestEvent>?>
}

override fun transform(): List<TestEvent>? {
val lines = buffer.lines()

val tokenPosition = lines.indexOfFirst {
it.startsWith(TokenType.INSTRUMENTATION_STATUS_CODE.name) ||
it.startsWith(TokenType.INSTRUMENTATION_CODE.name)
}
val tokenPosition = buffer.indexOfAny(
listOf(
TokenType.INSTRUMENTATION_STATUS_CODE.name,
TokenType.INSTRUMENTATION_CODE.name
)
)

if (tokenPosition == -1) {
return null
}

val atom = lines.subList(0, tokenPosition + 1)
buffer = buffer.delete(0, atom.map { it.length }.reduce { acc, i -> acc + i + 1 })
val nextLineBreak = buffer.indexOf('\n', startIndex = tokenPosition)


val atom = buffer.substring(0, nextLineBreak).lines()
buffer = buffer.delete(0, nextLineBreak + 1)

return parse(atom)
}
Expand Down Expand Up @@ -215,6 +218,7 @@ enum class Status(val value: Int) {
SUCCESS(0),
START(1),
IN_PROGRESS(2),

/**
* JUnit3 runner code, treated as FAILURE
*/
Expand Down

0 comments on commit 11b3075

Please sign in to comment.