Skip to content

Can StringName literals be optimized? #531

@Des-Nerger

Description

@Des-Nerger

If I've understood it correctly, constructing a StringName once and then doing .clone() of it is non-negligibly more efficient than constructing it of &str from scratch every time we need a StringName to pass to the Godot API. So, naturally, .clone() should be used quite often:

  fn init(base: Base<Self::Base>) -> Self {
    Self {
      velocity: Vector2::ZERO,
      input: Input::singleton(),
      ui_left: "ui_left".into(),
      ui_right: "ui_right".into(),
      ui_up: "ui_up".into(),
      ui_down: "ui_down".into(),
      base,
    }
  }

  fn process(&mut self, delta: f64) {
    let o /*bject */ = self;
    o.velocity =
      o.input.get_vector(o.ui_left.clone(), o.ui_right.clone(), o.ui_up.clone(), o.ui_down.clone());
    ...
  }

So, why not do #[derive(Copy)] on StringName to make it less hairy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: coreCore componentsquestionNot a problem with the library, but a question regarding usage.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions