Skip to content

Commit cc89a20

Browse files
authored
env.cc: avoid calling ok() if there is no exception handler (#1345)
1 parent a671c46 commit cc89a20

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

firestore/src/jni/env.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ Env::Env(JNIEnv* env)
5959
: env_(env), initial_pending_exceptions_(CurrentExceptionCount()) {}
6060

6161
Env::~Env() noexcept(false) {
62-
if (ok()) return;
62+
// Avoid calling ok() if there is no registered exception handler. It is
63+
// slightly more efficient in the common case that no exception handler is
64+
// specified, and also avoids calling into the JVM in the rare case that the
65+
// thread is already detached.
66+
if (!exception_handler_ || ok()) {
67+
return;
68+
}
6369

6470
if (exception_handler_ &&
6571
CurrentExceptionCount() == initial_pending_exceptions_) {

0 commit comments

Comments
 (0)