Skip to content

Commit

Permalink
refactor!: Optimize simple string getters
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell committed Dec 8, 2024
1 parent b4a89a3 commit b0a7a3c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
10 changes: 4 additions & 6 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ impl<'a> Node<'a> {
self.data().role()
}

pub fn role_description(&self) -> Option<String> {
self.data().role_description().map(String::from)
pub fn role_description(&self) -> Option<&str> {
self.data().role_description()
}

pub fn has_role_description(&self) -> bool {
Expand Down Expand Up @@ -524,10 +524,8 @@ impl<'a> Node<'a> {
.map(|description| description.to_string())
}

pub fn placeholder(&self) -> Option<String> {
self.data()
.placeholder()
.map(|placeholder| placeholder.to_string())
pub fn placeholder(&self) -> Option<&str> {
self.data().placeholder()
}

pub fn value(&self) -> Option<String> {
Expand Down
4 changes: 2 additions & 2 deletions platforms/atspi-common/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl NodeWrapper<'_> {
fn attributes(&self) -> HashMap<&'static str, String> {
let mut attributes = HashMap::new();
if let Some(placeholder) = self.0.placeholder() {
attributes.insert("placeholder-text", placeholder);
attributes.insert("placeholder-text", placeholder.to_string());
}
attributes
}
Expand Down Expand Up @@ -775,7 +775,7 @@ impl PlatformNode {
}

pub fn localized_role_name(&self) -> Result<String> {
self.resolve(|node| Ok(node.role_description().unwrap_or_default()))
self.resolve(|node| Ok(node.role_description().unwrap_or_default().to_string()))
}

pub fn state(&self) -> StateSet {
Expand Down
6 changes: 3 additions & 3 deletions platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl NodeWrapper<'_> {
self.0.description()
}

pub(crate) fn placeholder(&self) -> Option<String> {
pub(crate) fn placeholder(&self) -> Option<&str> {
self.0.placeholder()
}

Expand Down Expand Up @@ -452,7 +452,7 @@ declare_class!(
fn role_description(&self) -> Option<Id<NSString>> {
self.resolve(|node| {
if let Some(role_description) = node.role_description() {
Some(NSString::from_str(&role_description))
Some(NSString::from_str(role_description))
} else {
unsafe { msg_send_id![super(self), accessibilityRoleDescription] }
}
Expand Down Expand Up @@ -490,7 +490,7 @@ declare_class!(
fn placeholder(&self) -> Option<Id<NSString>> {
self.resolve(|node| {
let wrapper = NodeWrapper(node);
wrapper.placeholder().map(|placeholder| NSString::from_str(&placeholder))
wrapper.placeholder().map(|placeholder| NSString::from_str(placeholder))
})
.flatten()
}
Expand Down
4 changes: 2 additions & 2 deletions platforms/windows/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl NodeWrapper<'_> {
}
}

fn localized_control_type(&self) -> Option<String> {
fn localized_control_type(&self) -> Option<&str> {
self.0.role_description()
}

Expand All @@ -270,7 +270,7 @@ impl NodeWrapper<'_> {
self.0.description()
}

fn placeholder(&self) -> Option<String> {
fn placeholder(&self) -> Option<&str> {
self.0.placeholder()
}

Expand Down

0 comments on commit b0a7a3c

Please sign in to comment.