Skip to content

Commit

Permalink
perf: optimize running of user-set callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jun 17, 2021
1 parent e097884 commit 2319487
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Cache value of app.backgroundWorkRestricted
[#1275](https://github.com/bugsnag/bugsnag-android/pull/1275)

* Optimize execution of callbacks
[#1276](https://github.com/bugsnag/bugsnag-android/pull/1276)

## 5.9.4 (2021-05-26)

* Unity: add methods for setting autoNotify and autoDetectAnrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ internal data class CallbackState(
}

fun runOnErrorTasks(event: Event, logger: Logger): Boolean {
// optimization to avoid construction of iterator when no callbacks set
if (onErrorTasks.isEmpty()) {
return true
}
onErrorTasks.forEach {
try {
if (!it.onError(event)) {
Expand All @@ -46,6 +50,10 @@ internal data class CallbackState(
}

fun runOnBreadcrumbTasks(breadcrumb: Breadcrumb, logger: Logger): Boolean {
// optimization to avoid construction of iterator when no callbacks set
if (onBreadcrumbTasks.isEmpty()) {
return true
}
onBreadcrumbTasks.forEach {
try {
if (!it.onBreadcrumb(breadcrumb)) {
Expand All @@ -59,6 +67,10 @@ internal data class CallbackState(
}

fun runOnSessionTasks(session: Session, logger: Logger): Boolean {
// optimization to avoid construction of iterator when no callbacks set
if (onSessionTasks.isEmpty()) {
return true
}
onSessionTasks.forEach {
try {
if (!it.onSession(session)) {
Expand Down

0 comments on commit 2319487

Please sign in to comment.