Skip to main content

Optimizer

Struct Optimizer 

Source
pub struct Optimizer {
    pub last_css: String,
    pub optimization_level: OptimizationLevel,
    pub environment_config: EnvironmentOptimizationConfig,
}
Expand description

Nargo 优化器

负责对 IR 模块进行各种优化,包括常量折叠、死代码消除、静态提升等。

Fields§

§last_css: String

上次生成的 CSS

§optimization_level: OptimizationLevel

优化级别

§environment_config: EnvironmentOptimizationConfig

环境优化配置

Implementations§

Source§

impl Optimizer

Source

pub fn new() -> Self

创建新的优化器实例

Source

pub fn set_optimization_level(&mut self, level: OptimizationLevel)

设置优化级别

§Arguments
  • level - 优化级别
Source

pub fn set_environment_config(&mut self, config: EnvironmentOptimizationConfig)

设置环境优化配置

§Arguments
  • config - 环境优化配置
Source

pub fn set_target_environment(&mut self, target: TargetEnvironment)

设置目标环境

§Arguments
  • target - 目标环境
Source

pub fn optimize( &mut self, ir: &mut IRModule, locale: Option<&str>, is_prod: bool, )

优化 IR 模块

§Arguments
  • ir - IR 模块
  • locale - 国际化语言环境
  • is_prod - 是否为生产环境
Source

pub fn process_styles(&mut self, ir: &IRModule) -> Result<()>

处理样式

§Arguments
  • ir - IR 模块
§Returns

处理结果

Source

pub fn get_css(&self) -> String

获取生成的 CSS

§Returns

CSS 代码

Source

pub fn apply_scope_id(&mut self, ir: &mut IRModule, scope_id: &str)

应用作用域 ID

§Arguments
  • ir - IR 模块
  • scope_id - 作用域 ID
Source

pub fn generate_scope_id(&self, name: &str) -> String

生成作用域 ID

§Arguments
  • name - 组件名称
§Returns

作用域 ID

Source

pub fn set_detailed_optimizations(&mut self, enabled: bool)

设置是否启用详细优化(兼容旧接口)

§Arguments
  • enabled - 是否启用

Trait Implementations§

Source§

impl Default for Optimizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.