Skip to content

Commit 5f51343

Browse files
committed
Merge pull request #119 from iopq/fixes
Fixes for performance
2 parents 618c0df + 0987af2 commit 5f51343

File tree

11 files changed

+195
-90
lines changed

11 files changed

+195
-90
lines changed

src/board/chain/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* *
33
* Copyright 2014 Thomas Poinsot *
4-
* Copyright 2015 Urban Hafner *
4+
* Copyright 2015 Urban Hafner, Igor Polyakov *
55
* *
66
* This file is part of Iomrascálaí. *
77
* *
@@ -36,23 +36,25 @@ pub struct Chain {
3636
}
3737

3838
impl Chain {
39-
pub fn new(id: usize, color: Color, c: Coord, libs: Vec<Coord>) -> Chain {
39+
pub fn new(id: usize, color: Color, c: Coord, libs: HashSet<Coord>) -> Chain {
4040
Chain {
4141
color: color,
4242
coords: vec!(c),
4343
id: id,
44-
libs: libs.into_iter().collect(),
44+
libs: libs,
4545
}
4646
}
4747

4848
pub fn color(&self) -> Color {
4949
self.color
5050
}
5151

52+
#[inline(always)]
5253
pub fn coords<'a>(&'a self) -> &'a Vec<Coord> {
5354
&self.coords
5455
}
5556

57+
#[inline(always)]
5658
pub fn liberties(&self) -> &HashSet<Coord> {
5759
&self.libs
5860
}
@@ -65,18 +67,22 @@ impl Chain {
6567
self.id = id;
6668
}
6769

70+
#[inline(always)]
6871
pub fn add_liberty(&mut self, coord: Coord) {
6972
self.libs.insert(coord);
7073
}
7174

75+
#[inline(always)]
7276
pub fn remove_liberty(&mut self, coord: Coord) {
7377
self.libs.remove(&coord);
7478
}
7579

80+
#[inline(always)]
7681
pub fn add_coord(&mut self, coord: Coord) {
7782
self.coords.push(coord);
7883
}
7984

85+
#[inline(always)]
8086
pub fn is_captured(&self) -> bool {
8187
self.libs.len() == 0
8288
}

src/board/chain/test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
use board::Black;
44
use board::Chain;
55
use board::Coord;
6+
use std::collections::HashSet;
67

78
#[test]
89
fn show_returns_a_legible_string_for_the_chain() {
9-
let mut c = Chain::new(1, Black, Coord::new(7,7), vec!(Coord::new(1,1)));
10+
let mut set = HashSet::new();
11+
set.insert(Coord::new(1,1));
12+
let mut c = Chain::new(1, Black, Coord::new(7,7), set);
1013

1114
c.add_coord(Coord::new(7,8));
1215
c.add_coord(Coord::new(7,9));

src/board/coord/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* *
33
* Copyright 2014 Urban Hafner, Thomas Poinsot *
4-
* Copyright 2015 Urban Hafner *
4+
* Copyright 2015 Urban Hafner, Igor Polyakov *
55
* *
66
* This file is part of Iomrascálaí. *
77
* *
@@ -76,10 +76,12 @@ impl Coord {
7676
.collect()
7777
}
7878

79+
#[inline(always)]
7980
pub fn to_index(&self, board_size: u8) -> usize {
8081
(self.col as usize-1 + (self.row as usize-1)*board_size as usize)
8182
}
8283

84+
#[inline(always)]
8385
pub fn is_inside(&self, board_size: u8) -> bool {
8486
1 <= self.col && self.col <= board_size && 1 <= self.row && self.row <= board_size
8587
}

0 commit comments

Comments
 (0)