minor performance tweak

This commit is contained in:
David Rose 2005-01-29 01:08:53 +00:00
parent f010cd6573
commit 59ef5e9f80

View File

@ -226,12 +226,14 @@ set_type(PNMFileType *type) {
INLINE void PNMImageHeader:: INLINE void PNMImageHeader::
record_color(PNMImageHeader::Histogram &hist, record_color(PNMImageHeader::Histogram &hist,
const PNMImageHeader::PixelSpec &color) { const PNMImageHeader::PixelSpec &color) {
Histogram::iterator hi = hist.find(color); // First, try to add the color with a count of 0, in case it does
if (hi == hist.end()) { // not already exist in the table.
hist.insert(Histogram::value_type(color, 1)); Histogram::iterator hi = hist.insert(Histogram::value_type(color, 0)).first;
} else {
(*hi).second++; // Now that either succeeded or failed, but either way hi is now the
} // iterator to the count value in the table associated with the
// given color. Increment that count.
(*hi).second++;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////