Skip to content

Commit 484fd7c

Browse files
authored
refactor!: Optimize simple string getters (#493)
1 parent 089794c commit 484fd7c

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

consumer/src/node.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ impl<'a> Node<'a> {
326326
self.data().role()
327327
}
328328

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

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

527-
pub fn placeholder(&self) -> Option<String> {
528-
self.data()
529-
.placeholder()
530-
.map(|placeholder| placeholder.to_string())
527+
pub fn placeholder(&self) -> Option<&str> {
528+
self.data().placeholder()
531529
}
532530

533531
pub fn value(&self) -> Option<String> {

platforms/atspi-common/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl NodeWrapper<'_> {
355355
fn attributes(&self) -> HashMap<&'static str, String> {
356356
let mut attributes = HashMap::new();
357357
if let Some(placeholder) = self.0.placeholder() {
358-
attributes.insert("placeholder-text", placeholder);
358+
attributes.insert("placeholder-text", placeholder.to_string());
359359
}
360360
attributes
361361
}
@@ -775,7 +775,7 @@ impl PlatformNode {
775775
}
776776

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

781781
pub fn state(&self) -> StateSet {

platforms/macos/src/node.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl NodeWrapper<'_> {
316316
self.0.description()
317317
}
318318

319-
pub(crate) fn placeholder(&self) -> Option<String> {
319+
pub(crate) fn placeholder(&self) -> Option<&str> {
320320
self.0.placeholder()
321321
}
322322

@@ -452,7 +452,7 @@ declare_class!(
452452
fn role_description(&self) -> Option<Id<NSString>> {
453453
self.resolve(|node| {
454454
if let Some(role_description) = node.role_description() {
455-
Some(NSString::from_str(&role_description))
455+
Some(NSString::from_str(role_description))
456456
} else {
457457
unsafe { msg_send_id![super(self), accessibilityRoleDescription] }
458458
}
@@ -490,7 +490,7 @@ declare_class!(
490490
fn placeholder(&self) -> Option<Id<NSString>> {
491491
self.resolve(|node| {
492492
let wrapper = NodeWrapper(node);
493-
wrapper.placeholder().map(|placeholder| NSString::from_str(&placeholder))
493+
wrapper.placeholder().map(NSString::from_str)
494494
})
495495
.flatten()
496496
}

platforms/windows/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl NodeWrapper<'_> {
254254
}
255255
}
256256

257-
fn localized_control_type(&self) -> Option<String> {
257+
fn localized_control_type(&self) -> Option<&str> {
258258
self.0.role_description()
259259
}
260260

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

273-
fn placeholder(&self) -> Option<String> {
273+
fn placeholder(&self) -> Option<&str> {
274274
self.0.placeholder()
275275
}
276276

0 commit comments

Comments
 (0)