Skip to content

Commit

Permalink
ManagedBufferBuilder removed cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 5, 2024
1 parent 38e452d commit 3667386
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions framework/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ all-features = true
[features]
num-bigint = ["multiversx-sc-codec/num-bigint"]
alloc = ["multiversx-sc-codec/alloc"]
managed-buffer-builder-cached = []
esdt-token-payment-legacy-decode = []

[dependencies]
Expand Down
7 changes: 7 additions & 0 deletions framework/base/src/types/managed/wrapped/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
mod managed_buffer_builder;
mod managed_buffer_builder_impl;
mod managed_buffer_builder_impl_basic;
mod managed_buffer_builder_impl_cached;

pub use managed_buffer_builder::ManagedBufferBuilder;
pub use managed_buffer_builder_impl::ManagedBufferBuilderImpl;
pub use managed_buffer_builder_impl_basic::ManagedBufferBuilderImplBasic;
pub use managed_buffer_builder_impl_cached::ManagedBufferBuilderImplCached;

#[deprecated(since = "0.48.0", note = "Renamed to ManagedBufferBuilder.")]
pub type ManagedBufferCachedBuilder<M> = ManagedBufferBuilder<M>;

#[cfg(feature = "managed-buffer-builder-cached")]
pub type ManagedBufferImplDefault<M> = ManagedBufferBuilderImplCached<M>;

#[cfg(not(feature = "managed-buffer-builder-cached"))]
pub type ManagedBufferImplDefault<M> = ManagedBufferBuilderImplBasic<M>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{api::ManagedTypeApi, types::ManagedBuffer};

use super::ManagedBufferBuilderImpl;

/// Basic implementation of a ManagedBuffer builder, no caching.
///
/// It is the ManagedBuffer itself, we just append to it each time.
pub struct ManagedBufferBuilderImplBasic<M>
where
M: ManagedTypeApi,
{
managed_buffer: ManagedBuffer<M>,
}

impl<M> ManagedBufferBuilderImpl<M> for ManagedBufferBuilderImplBasic<M>
where
M: ManagedTypeApi,
{
#[inline]
fn new_from_slice(slice: &[u8]) -> Self {
ManagedBufferBuilderImplBasic {
managed_buffer: slice.into(),
}
}

#[inline]
fn into_managed_buffer(self) -> ManagedBuffer<M> {
self.managed_buffer
}

#[inline]
fn append_bytes(&mut self, bytes: &[u8]) {
self.managed_buffer.append_bytes(bytes);
}

#[inline]
fn append_managed_buffer(&mut self, item: &ManagedBuffer<M>) {
self.managed_buffer.append(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{

use super::ManagedBufferBuilderImpl;

/// A ManagedBuffer builder implementation that caches data to the static cache locally in the contract.
pub struct ManagedBufferBuilderImplCached<M>
where
M: ManagedTypeApi,
Expand Down

0 comments on commit 3667386

Please sign in to comment.