Skip to content

Commit 0b7d563

Browse files
authored
Use intern macro for getattr strings (#39)
1 parent 1b1da04 commit 0b7d563

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/sprite_list.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::geometry::are_polygons_intersecting_native;
22
use crate::hitbox::{HitBox, NativeAdjustedPoints, RotatableHitBox};
3+
use pyo3::intern;
34
use pyo3::prelude::*;
45

56
#[pyfunction]
@@ -15,7 +16,7 @@ pub fn check_for_collision_with_list(
1516
let main_points: &Vec<(f32, f32)>;
1617
let mut hitbox1: HitBox;
1718
let mut hitbox2: RotatableHitBox;
18-
let hitbox_py_object: &PyAny = sprite.getattr("_hit_box").unwrap();
19+
let hitbox_py_object: &PyAny = sprite.getattr(intern!(py, "_hit_box")).unwrap();
1920

2021
if hitbox_py_object.is_instance_of::<HitBox>() {
2122
hitbox1 = hitbox_py_object.extract::<HitBox>().unwrap();
@@ -27,7 +28,7 @@ pub fn check_for_collision_with_list(
2728
panic!("Unknown Hitbox Type")
2829
}
2930

30-
let sprite_list_list = sprite_list.getattr("sprite_list").unwrap();
31+
let sprite_list_list = sprite_list.getattr(intern!(py, "sprite_list")).unwrap();
3132
let sprites_to_check: Vec<PyObject> = sprite_list_list.extract().unwrap();
3233

3334
for sprite2 in sprites_to_check.iter() {
@@ -36,7 +37,7 @@ pub fn check_for_collision_with_list(
3637
let other_points: &Vec<(f32, f32)>;
3738
let mut other_hitbox1: HitBox;
3839
let mut other_hitbox2: RotatableHitBox;
39-
let other_hitbox_py_object: &PyAny = other_sprite.getattr("_hit_box").unwrap();
40+
let other_hitbox_py_object: &PyAny = other_sprite.getattr(intern!(py, "_hit_box")).unwrap();
4041

4142
if other_hitbox_py_object.is_instance_of::<HitBox>() {
4243
other_hitbox1 = other_hitbox_py_object.extract::<HitBox>().unwrap();
@@ -69,7 +70,7 @@ pub fn check_for_collision_with_lists(
6970
let main_points: &Vec<(f32, f32)>;
7071
let mut hitbox1: HitBox;
7172
let mut hitbox2: RotatableHitBox;
72-
let hitbox_py_object: &PyAny = sprite.getattr("_hit_box").unwrap();
73+
let hitbox_py_object: &PyAny = sprite.getattr(intern!(py, "_hit_box")).unwrap();
7374

7475
if hitbox_py_object.is_instance_of::<HitBox>() {
7576
hitbox1 = hitbox_py_object.extract::<HitBox>().unwrap();
@@ -82,7 +83,7 @@ pub fn check_for_collision_with_lists(
8283
}
8384

8485
for sprite_list in sprite_lists.iter() {
85-
let sprite_list_list = sprite_list.getattr("sprite_list").unwrap();
86+
let sprite_list_list = sprite_list.getattr(intern!(py, "sprite_list")).unwrap();
8687
let sprites_to_check: Vec<PyObject> = sprite_list_list.extract().unwrap();
8788

8889
for sprite2 in sprites_to_check.iter() {
@@ -91,7 +92,8 @@ pub fn check_for_collision_with_lists(
9192
let other_points: &Vec<(f32, f32)>;
9293
let mut other_hitbox1: HitBox;
9394
let mut other_hitbox2: RotatableHitBox;
94-
let other_hitbox_py_object: &PyAny = other_sprite.getattr("_hit_box").unwrap();
95+
let other_hitbox_py_object: &PyAny =
96+
other_sprite.getattr(intern!(py, "_hit_box")).unwrap();
9597

9698
if other_hitbox_py_object.is_instance_of::<HitBox>() {
9799
other_hitbox1 = other_hitbox_py_object.extract::<HitBox>().unwrap();

0 commit comments

Comments
 (0)