Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise by not cloning key #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/read_ply_to_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ply::PropertyAccess for Vertex {
z: 0.0,
}
}
fn set_property(&mut self, key: String, property: ply::Property) {
fn set_property(&mut self, key: &String, property: ply::Property) {
match (key.as_ref(), property) {
("x", ply::Property::Float(v)) => self.x = v,
("y", ply::Property::Float(v)) => self.y = v,
Expand All @@ -46,7 +46,7 @@ impl ply::PropertyAccess for Face {
vertex_index: Vec::new(),
}
}
fn set_property(&mut self, key: String, property: ply::Property) {
fn set_property(&mut self, key: &String, property: ply::Property) {
match (key.as_ref(), property) {
("vertex_index", ply::Property::ListInt(vec)) => self.vertex_index = vec,
(k, _) => panic!("Face: Unexpected key/value combination: key: {}", k),
Expand Down
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<E: PropertyAccess> Parser<E> {
let mut vals = E::new();
for (k, p) in &element_def.properties {
let new_p : Property = self.__read_ascii_property(&mut elem_it, &p.data_type)?;
vals.set_property(k.clone(), new_p);
vals.set_property(k, new_p);
}
Ok(vals)
}
Expand Down Expand Up @@ -480,7 +480,7 @@ impl<E: PropertyAccess> Parser<E> {

for (k, p) in &element_def.properties {
let property = self.__read_binary_property::<T, B>(reader, &p.data_type)?;
raw_element.set_property(k.clone(), property);
raw_element.set_property(k, property);
}
Ok(raw_element)
}
Expand Down
4 changes: 2 additions & 2 deletions src/ply/default_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl PropertyAccess for DefaultElement {
fn new() -> Self {
DefaultElement::new()
}
fn set_property(&mut self, key: String, property: Property) {
self.insert(key, property);
fn set_property(&mut self, key: &String, property: Property) {
self.insert(key.to_string(), property);
}
fn get_char(&self, key: &String) -> Option<i8> {
match *get!(self.get(key)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ply/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub enum Property {
/// The getters are named in congruence with `PropertyType` and `ScalarType`.
pub trait PropertyAccess {
fn new() -> Self;
fn set_property(&mut self, _property_name: String, _property: Property) {
fn set_property(&mut self, _property_name: &String, _property: Property) {
// By default, do nothing
// Sombody might only want to write, no point in bothering him/her with setter implementations.
}
Expand Down
8 changes: 4 additions & 4 deletions tests/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ mod struct_test_1 {
z: 0.0,
}
}
fn set_property(&mut self, key: String, property: ply::Property) {
match (key.as_ref(), property) {
fn set_property(&mut self, key: &String, property: ply::Property) {
match (key.as_str(), property) {
("x", ply::Property::Float(v)) => self.x = v,
("y", ply::Property::Float(v)) => self.y = v,
("z", ply::Property::Float(v)) => self.z = v,
Expand All @@ -109,8 +109,8 @@ mod struct_test_1 {
vertex_index: Vec::new(),
}
}
fn set_property(&mut self, key: String, property: ply::Property) {
match (key.as_ref(), property) {
fn set_property(&mut self, key: &String, property: ply::Property) {
match (key.as_str(), property) {
("vertex_index", ply::Property::ListInt(vec)) => self.vertex_index = vec,
(k, _) => panic!("Face: Unexpected key/value combination: key: {}", k),
}
Expand Down