Skip to content

Commit dc264f6

Browse files
authored
Merge pull request #1376 from sdroege/dont-list-properties
glib: Don't use `g_object_list_properties()` for setting properties
2 parents 6536e86 + 6c07de4 commit dc264f6

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

glib/src/object.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,12 +1449,10 @@ impl Object {
14491449
if !properties.is_empty() {
14501450
let klass = ObjectClass::from_type(type_)
14511451
.unwrap_or_else(|| panic!("Can't retrieve class for type '{type_}'"));
1452-
let pspecs = klass.list_properties();
14531452

14541453
for (idx, (name, value)) in properties.iter_mut().enumerate() {
1455-
let pspec = pspecs
1456-
.iter()
1457-
.find(|p| p.name() == *name)
1454+
let pspec = klass
1455+
.find_property(name)
14581456
.unwrap_or_else(|| panic!("Can't find property '{name}' for type '{type_}'"));
14591457

14601458
if (pspec.flags().contains(crate::ParamFlags::CONSTRUCT)
@@ -1469,7 +1467,7 @@ impl Object {
14691467
// FIXME: With GLib 2.74 and GParamSpecClass::value_is_valid() it is possible to
14701468
// not require mutable values here except for when LAX_VALIDATION is provided and a
14711469
// change is needed, or a GObject value needs it's GType changed.
1472-
validate_property_type(type_, true, pspec, value);
1470+
validate_property_type(type_, true, &pspec, value);
14731471

14741472
property_names.push(pspec.name().as_ptr());
14751473
property_values.push(*value.to_glib_none().0);
@@ -2278,17 +2276,15 @@ impl<T: ObjectType> ObjectExt for T {
22782276

22792277
#[track_caller]
22802278
fn set_properties(&self, property_values: &[(&str, &dyn ToValue)]) {
2281-
let pspecs = self.list_properties();
2282-
22832279
let params = property_values
22842280
.iter()
22852281
.map(|&(name, value)| {
2286-
let pspec = pspecs.iter().find(|p| p.name() == name).unwrap_or_else(|| {
2282+
let pspec = self.find_property(name).unwrap_or_else(|| {
22872283
panic!("Can't find property '{name}' for type '{}'", self.type_());
22882284
});
22892285

22902286
let mut value = value.to_value();
2291-
validate_property_type(self.type_(), false, pspec, &mut value);
2287+
validate_property_type(self.type_(), false, &pspec, &mut value);
22922288
(pspec.name().as_ptr(), value)
22932289
})
22942290
.collect::<smallvec::SmallVec<[_; 10]>>();
@@ -2307,20 +2303,15 @@ impl<T: ObjectType> ObjectExt for T {
23072303

23082304
#[track_caller]
23092305
fn set_properties_from_value(&self, property_values: &[(&str, Value)]) {
2310-
let pspecs = self.list_properties();
2311-
23122306
let params = property_values
23132307
.iter()
23142308
.map(|(name, value)| {
2315-
let pspec = pspecs
2316-
.iter()
2317-
.find(|p| p.name() == *name)
2318-
.unwrap_or_else(|| {
2319-
panic!("Can't find property '{name}' for type '{}'", self.type_());
2320-
});
2309+
let pspec = self.find_property(name).unwrap_or_else(|| {
2310+
panic!("Can't find property '{name}' for type '{}'", self.type_());
2311+
});
23212312

23222313
let mut value = value.clone();
2323-
validate_property_type(self.type_(), false, pspec, &mut value);
2314+
validate_property_type(self.type_(), false, &pspec, &mut value);
23242315
(pspec.name().as_ptr(), value)
23252316
})
23262317
.collect::<smallvec::SmallVec<[_; 10]>>();

0 commit comments

Comments
 (0)