Skip to content

Commit

Permalink
Cleanup Fresco SystraceRequestRequestListener (#46626)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46626

Remove `!!` by reusing lookup result.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D63316175

fbshipit-source-id: 1abfb20490831f26819aef4393c9629253d33ec6
  • Loading branch information
javache authored and facebook-github-bot committed Sep 24, 2024
1 parent 303e0ed commit 0cb32d5
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.facebook.systrace.Systrace
/** Logs requests to Systrace */
public class SystraceRequestListener : BaseRequestListener() {
private var currentId: Int = 0
private var producerId: MutableMap<String, Pair<Int, String>> = mutableMapOf()
private var requestsId: MutableMap<String, Pair<Int, String>> = mutableMapOf()
private val producerId: MutableMap<String, Pair<Int, String>> = mutableMapOf()
private val requestsId: MutableMap<String, Pair<Int, String>> = mutableMapOf()

override fun onProducerStart(requestId: String, producerName: String) {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
Expand All @@ -39,8 +39,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (producerId.containsKey(requestId)) {
val entry = producerId[requestId]!!

val entry = producerId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
producerId.remove(requestId)
}
Expand All @@ -55,8 +56,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (producerId.containsKey(requestId)) {
val entry = producerId[requestId]!!

val entry = producerId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
producerId.remove(requestId)
}
Expand All @@ -70,8 +72,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (producerId.containsKey(requestId)) {
val entry = producerId[requestId]!!

val entry = producerId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
producerId.remove(requestId)
}
Expand Down Expand Up @@ -101,6 +104,7 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}

val entryName = StringBuilder()
entryName.append("FRESCO_REQUEST_")
entryName.append(request.sourceUri.toString().replace(':', '_'))
Expand All @@ -114,8 +118,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (requestsId.containsKey(requestId)) {
val entry = requestsId[requestId]!!

val entry = requestsId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
requestsId.remove(requestId)
}
Expand All @@ -130,8 +135,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (requestsId.containsKey(requestId)) {
val entry = requestsId[requestId]!!

val entry = requestsId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
requestsId.remove(requestId)
}
Expand All @@ -141,8 +147,9 @@ public class SystraceRequestListener : BaseRequestListener() {
if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
return
}
if (requestsId.containsKey(requestId)) {
val entry = requestsId[requestId]!!

val entry = requestsId[requestId]
if (entry != null) {
Systrace.endAsyncSection(Systrace.TRACE_TAG_REACT_FRESCO, entry.second, entry.first)
requestsId.remove(requestId)
}
Expand Down

0 comments on commit 0cb32d5

Please sign in to comment.