Skip to content

Commit 6d44333

Browse files
Use lookup_table
1 parent 44b4eb8 commit 6d44333

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Include/internal/pycore_backoff.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ extern "C" {
3737
#define UNREACHABLE_BACKOFF 7
3838
#define MAX_VALUE 0x1FFF
3939

40+
// We only use values x such that x + 1 is prime.
41+
static const int lookup_table[] = {1, 6, 30, 126, 508, 2052, 8190, 8190};
42+
4043
static inline _Py_BackoffCounter
4144
make_backoff_counter(uint16_t value, uint16_t backoff)
4245
{
@@ -61,8 +64,7 @@ restart_backoff_counter(_Py_BackoffCounter counter)
6164
uint16_t backoff = counter.value_and_backoff & BACKOFF_MASK;
6265
assert(backoff <= MAX_BACKOFF);
6366
backoff = (backoff == MAX_BACKOFF) ? backoff : backoff + 1;
64-
uint16_t value = (1 << (2 * backoff + 1)) - 1;
65-
return make_backoff_counter(value, backoff);
67+
return make_backoff_counter(lookup_table[backoff], backoff);
6668
}
6769

6870
static inline _Py_BackoffCounter

0 commit comments

Comments
 (0)