Skip to content

Commit

Permalink
Merge pull request #1276 from bugsnag/PLAT-6752/callback-optimization
Browse files Browse the repository at this point in the history
Optimize execution of callbacks
  • Loading branch information
fractalwrench authored Jun 17, 2021
2 parents e097884 + 2319487 commit e4cf4bc
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 e4cf4bc

Please sign in to comment.