Skip to content

Commit 71bfc9c

Browse files
authored
Use in-place operators in enum mask calculations (#1138)
Since they are now available, use them instead of the tp.attr() assignment strategy, which is harder to read. No functional changes intended.
1 parent dae48e5 commit 71bfc9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/nb_enum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ void enum_append(PyObject *tp_, const char *name_, int64_t value_,
141141
// In Python 3.11+, update the flag and bit masks by hand,
142142
// since enum._proto_member.__set_name__ is not called in this code path.
143143
if (t->flags & (uint32_t) enum_flags::is_flag) {
144-
setattr(tp, "_flag_mask_", tp.attr("_flag_mask_") | val);
144+
tp.attr("_flag_mask_") |= val;
145145

146146
bool is_single_bit = (value_ != 0) && (value_ & (value_ - 1)) == 0;
147147
if (is_single_bit && hasattr(tp, "_singles_mask_"))
148-
setattr(tp, "_singles_mask_", tp.attr("_singles_mask_") | val);
148+
tp.attr("_singles_mask_") |= val;
149149

150150
int_ bit_length = int_(tp.attr("_flag_mask_").attr("bit_length")());
151151
setattr(tp, "_all_bits_", (int_(2) << bit_length) - int_(1));

0 commit comments

Comments
 (0)