Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem;

/// A string builder for constructing source code.
///
///
Expand Down Expand Up @@ -331,16 +333,11 @@ impl CodeBuffer {
/// ```
#[must_use]
pub fn take_source_text(&mut self) -> String {
use std::mem::take;

#[cfg(debug_assertions)]
{
String::from_utf8(take(&mut self.buf)).unwrap()
}
#[cfg(not(debug_assertions))]
{
if cfg!(debug_assertions) {
String::from_utf8(mem::take(&mut self.buf)).unwrap()
} else {
// SAFETY: All methods of `CodeBuffer` ensure `buf` is valid UTF-8
unsafe { String::from_utf8_unchecked(take(&mut self.buf)) }
unsafe { String::from_utf8_unchecked(mem::take(&mut self.buf)) }
}
}
}
Expand Down