Optimize cartridge Bus reads

The `if let Some(gpio) = &self.gpio` causes a memory read of `self.gpio` for every Bus::read/write_16.
It is better to reverse the order since `is_gpio_access` does not generate and memory reads and thus less costly.


Former-commit-id: bcce7d9c3a2b159a7f6b291d7b08ccf9c4d0db14
Former-commit-id: 69c12db503c9e612faa7cd8a57f6d862694c8370
This commit is contained in:
Michel Heily 2020-10-05 23:19:00 -07:00 committed by MishMish
parent 8dee829e26
commit bf601404fa

View file

@ -85,8 +85,8 @@ impl Bus for Cartridge {
}
fn read_16(&self, addr: u32) -> u16 {
if let Some(gpio) = &self.gpio {
if is_gpio_access(addr) {
if is_gpio_access(addr) {
if let Some(gpio) = &self.gpio {
if !(gpio.is_readable()) {
warn!("trying to read GPIO when reads are not allowed");
}
@ -116,8 +116,8 @@ impl Bus for Cartridge {
}
fn write_16(&mut self, addr: u32, value: u16) {
if let Some(gpio) = &mut self.gpio {
if is_gpio_access(addr) {
if is_gpio_access(addr) {
if let Some(gpio) = &mut self.gpio {
gpio.write(addr & 0x1ff_ffff, value);
return;
}