Skip to content

Commit c375981

Browse files
committed
refactor(napi/oxlint): simplify atomic operations (#12425)
`AtomicBool::store` does the same as `fetch_and(false)` / `fetch_or(true)`, is simpler, and possibly a little bit cheaper. Not sure why I didn't use it in the first place in #12381!
1 parent f125ee3 commit c375981

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

crates/oxc_allocator/src/pool_fixed_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub unsafe fn free_fixed_size_allocator(metadata_ptr: NonNull<FixedSizeAllocator
324324
// so going with `Ordering::SeqCst` to be on safe side.
325325
// Deallocation only happens at the end of the whole process, so it shouldn't matter much.
326326
// TODO: Figure out if can use `Ordering::Relaxed`.
327-
let is_double_owned = metadata.is_double_owned.fetch_and(false, Ordering::SeqCst);
327+
let is_double_owned = metadata.is_double_owned.swap(false, Ordering::SeqCst);
328328
if is_double_owned {
329329
return;
330330
}

napi/oxlint2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn wrap_run(cb: JsRunCb) -> ExternalLinterCb {
6262
// stored at the pointer returned by `Allocator::fixed_size_metadata_ptr`.
6363
let metadata = unsafe { metadata_ptr.as_ref() };
6464
// TODO: Is `Ordering::SeqCst` excessive here?
65-
let already_sent_to_js = metadata.is_double_owned.fetch_or(true, Ordering::SeqCst);
65+
let already_sent_to_js = metadata.is_double_owned.swap(true, Ordering::SeqCst);
6666

6767
(metadata.id, already_sent_to_js)
6868
};

0 commit comments

Comments
 (0)