Remove all the range checking from Bitmap
This commit is contained in:
		
							parent
							
								
									99d3e85ba5
								
							
						
					
					
						commit
						1daa3df74e
					
				
					 1 changed files with 5 additions and 22 deletions
				
			
		| 
						 | 
				
			
			@ -43,39 +43,29 @@ struct Bitmap
 | 
			
		|||
    isSet(usize bit)
 | 
			
		||||
        const
 | 
			
		||||
    {
 | 
			
		||||
        if (isValid(bit)) {
 | 
			
		||||
            return (mBitmap & (1 << bit)) > 0;
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
        return (mBitmap & FieldType(1 << bit)) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Set a single bit to 1. */
 | 
			
		||||
    void
 | 
			
		||||
    set(usize bit)
 | 
			
		||||
    {
 | 
			
		||||
        if (isValid(bit)) {
 | 
			
		||||
            mBitmap |= 1 << bit;
 | 
			
		||||
        }
 | 
			
		||||
        mBitmap |= FieldType(1 << bit);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Set a single bit to zero. */
 | 
			
		||||
    void
 | 
			
		||||
    clear(usize bit)
 | 
			
		||||
    {
 | 
			
		||||
        if (isValid(bit)) {
 | 
			
		||||
            mBitmap &= ~(1 << bit);
 | 
			
		||||
        }
 | 
			
		||||
        mBitmap &= ~FieldType(1 << bit);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Toggle the state of a single bit. Returns `true` if the bit was set to 1. */
 | 
			
		||||
    bool
 | 
			
		||||
    toggle(usize bit)
 | 
			
		||||
    {
 | 
			
		||||
        if (isValid(bit)) {
 | 
			
		||||
            mBitmap ^= 1 << bit;
 | 
			
		||||
            return isSet(bit);
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
        mBitmap ^= FieldType(1 << bit);
 | 
			
		||||
        return isSet(bit);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Clear the entire bit field. */
 | 
			
		||||
| 
						 | 
				
			
			@ -101,13 +91,6 @@ struct Bitmap
 | 
			
		|||
 | 
			
		||||
private:
 | 
			
		||||
    FieldType mBitmap;
 | 
			
		||||
 | 
			
		||||
    inline bool
 | 
			
		||||
    isValid(usize bit)
 | 
			
		||||
        const
 | 
			
		||||
    {
 | 
			
		||||
        return bit >= 0 && bit < Bitmap::length;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace kstd */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue