mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(codegen): shorten CodeBuffer::take_source_text (#6495)
Pure refactor.
This commit is contained in:
parent
951def6e35
commit
5843e01bed
1 changed files with 6 additions and 9 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::mem;
|
||||
|
||||
/// A string builder for constructing source code.
|
||||
///
|
||||
///
|
||||
|
|
@ -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)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue