code: @Override
  	public long writeBooleans(boolean value, long count) {
  		count = Math.min(count, size - position - bufferSize);
  		if (count == 0) return 0;
  
  		final int bits = value ? -1 : 0;
  		long c = count;
  		while (c >= 32) {
  			flushBuffer();
  			bufferBits = bits;
  			bufferSize = 32;
  			c -= 32;
  		}
  
  		int d = (int) c;
  		if (d == 0) {
  			/* do nothing */
  		} else if (bufferSize == 0) {
  			bufferBits = bits;
  			bufferSize = d;
  		} else if (bufferSize + d <= 32) {
  			bufferBits <<= d;
  			if (value) bufferBits |= preMask(d);
  			bufferSize += d;
  		} else {
  			flushBuffer();
  			bufferBits = bits;
  			bufferSize = d;
  		}
  
  		return count;
  	}
docs: optimized implementation