Skip to content

Commit

Permalink
refactor(codegen): inline CodeBuffer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 13, 2024
1 parent 40d1ee4 commit e45e5c5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl CodeBuffer {
/// code.print_str("fn main() { println!(\"Hello, world!\"); }");
/// let source_text = code.take_source_text();
/// ```
#[inline]
pub fn new() -> Self {
Self::default()
}
Expand All @@ -62,6 +63,7 @@ impl CodeBuffer {
/// # Panics
///
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Self { buf: Vec::with_capacity(capacity) }
}
Expand All @@ -70,6 +72,7 @@ impl CodeBuffer {
///
/// This is _not_ the same as the number of characters in the buffer, since
/// non-ASCII characters require multiple bytes.
#[inline]
pub fn len(&self) -> usize {
self.buf.len()
}
Expand All @@ -85,6 +88,7 @@ impl CodeBuffer {
/// code.print_char('c');
/// assert!(!code.is_empty());
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
self.buf.is_empty()
}
Expand Down Expand Up @@ -336,6 +340,7 @@ impl CodeBuffer {
/// assert!(code.is_empty());
/// ```
#[must_use]
#[inline]
pub fn take_source_text(&mut self) -> String {
if cfg!(debug_assertions) {
String::from_utf8(mem::take(&mut self.buf)).unwrap()
Expand All @@ -347,6 +352,7 @@ impl CodeBuffer {
}

impl AsRef<[u8]> for CodeBuffer {
#[inline]
fn as_ref(&self) -> &[u8] {
self.as_bytes()
}
Expand Down

0 comments on commit e45e5c5

Please sign in to comment.