diff options
author | Adam Borowski <kilobyte@angband.pl> | 2013-11-25 04:55:59 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2013-11-25 05:11:38 +0100 |
commit | a37dd589bb18013b3ad588c2df7409553cb33935 (patch) | |
tree | 66231734aacd3f21016cca81075e673167f70ed3 /crawl-ref/source/coordit.cc | |
parent | 24c2e89fad680da9e98b9a6b998a060852a8b9e0 (diff) | |
download | crawl-ref-a37dd589bb18013b3ad588c2df7409553cb33935.tar.gz crawl-ref-a37dd589bb18013b3ad588c2df7409553cb33935.zip |
Implement adjacent_iterator on its own, rather than via radius_iterator.
This hardly speeds up things, which I did not know as profile runs did not
help to tell these two apart and it turns out adjacent_iterator is not that
prominent... but hey, a 0.1% speedup for two pages of code might still be
better committed than not.
This speedup might disappear when I get around to the actual rewrite of
radius_iterator, though.
Diffstat (limited to 'crawl-ref/source/coordit.cc')
-rw-r--r-- | crawl-ref/source/coordit.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crawl-ref/source/coordit.cc b/crawl-ref/source/coordit.cc index f23e59dfce..52230f8cbf 100644 --- a/crawl-ref/source/coordit.cc +++ b/crawl-ref/source/coordit.cc @@ -270,6 +270,41 @@ void radius_iterator::operator++(int dummy) } /* + * adjacent iterator + */ +extern const struct coord_def Compass[9]; + +adjacent_iterator::operator bool() const +{ + return i >= 0; +} + +coord_def adjacent_iterator::operator *() const +{ + return val; +} + +const coord_def* adjacent_iterator::operator->() const +{ + return &val; +} + +void adjacent_iterator::operator ++() +{ + while (--i >= 0) + { + val = center + Compass[i]; + if (map_bounds(val)) + return; + } +} + +void adjacent_iterator::operator++(int dummy) +{ + ++(*this); +} + +/* * spiral iterator */ distance_iterator::distance_iterator(const coord_def& _center, bool _fair, |