<commit_before>package com.srs.tetris.game;

/**
 * A grid of squares, each of which can be filled or empty.
 */
public class BitBoard extends AbstractBoard<Boolean> {

	// The maximum width is limited to th
	private static final int MAX_WIDTH = 32;

	// A bit board, with one element per row.
	private int[] grid;

	// The mask for a full line.
	private int lineMask;

	public BitBoard(int width, int height) {
		super(width, height);
		this.grid = new int[height];

		if (this.getWidth() > MAX_WIDTH) {
			throw new IllegalArgumentException(String.format("width=%d, must be %d or less", getWidth(), MAX_WIDTH));
		}

		this.lineMask = (int) ((1L << width) - 1);
	}

	public BitBoard(int[][] grid) {
		this(grid[0].length, grid.length);

		for (int y = 0; y < getHeight(); y++) {
			for (int x = 0; x < getWidth(); x++) {
				set(x, y, grid[y][x] != 0);
			}
		}
	}

	public int[][] getGrid() {
		int[][] output = new int[getHeight()][getWidth()];
		for (int x = 0; x < getWidth(); x++) {
			for (int y = 0; y < getHeight(); y++) {
				output[y][x] = get(x, y) ? 1 : 0;
			}
		}
		return output;
	}

	@Override
	public boolean isEmpty(int x, int y) {
		return !get(x, y);
	}

	@Override
	public void remove(int x, int y) {
		set(x, y, false);
	}

	@Override
	public Boolean get(int x, int y) {
		assertRange(x, y);
		return (grid[y] & mask(x)) > 0;
	}

	@Override
	public void set(int x, int y, Boolean value) {
		assertRange(x, y);
		if (value) {
			grid[y] |= mask(x);
		} else {
			grid[y] &= ~mask(x);
		}
	}

	private int mask(int x) {
		return 1 << x;
	}

	@Override
	public void place(Piece piece) {
		place(piece.getBoard(), piece.getX(), piece.getY());
	}<commit_msg>Optimize for isEmpty since it is called far more often<commit_after>package com.srs.tetris.game;

/**
 * A grid of squares, each of which can be filled or empty.
 */
public class BitBoard extends AbstractBoard<Boolean> {

	// The maximum width is limited to th
	private static final int MAX_WIDTH = 32;

	// A bit board, with one element per row.
	private int[] grid;

	// The mask for a full line.
	private int lineMask;

	public BitBoard(int width, int height) {
		super(width, height);
		this.grid = new int[height];

		if (this.getWidth() > MAX_WIDTH) {
			throw new IllegalArgumentException(String.format("width=%d, must be %d or less", getWidth(), MAX_WIDTH));
		}

		this.lineMask = (int) ((1L << width) - 1);
	}

	public BitBoard(int[][] grid) {
		this(grid[0].length, grid.length);

		for (int y = 0; y < getHeight(); y++) {
			for (int x = 0; x < getWidth(); x++) {
				set(x, y, grid[y][x] != 0);
			}
		}
	}

	public int[][] getGrid() {
		int[][] output = new int[getHeight()][getWidth()];
		for (int x = 0; x < getWidth(); x++) {
			for (int y = 0; y < getHeight(); y++) {
				output[y][x] = get(x, y) ? 1 : 0;
			}
		}
		return output;
	}

	@Override
	public boolean isEmpty(int x, int y) {
		assertRange(x, y);
		return (grid[y] & mask(x)) == 0;
	}

	@Override
	public void remove(int x, int y) {
		set(x, y, false);
	}

	@Override
	public Boolean get(int x, int y) {
		assertRange(x, y);
		return !isEmpty(x, y);
	}

	@Override
	public void set(int x, int y, Boolean value) {
		assertRange(x, y);
		if (value) {
			grid[y] |= mask(x);
		} else {
			grid[y] &= ~mask(x);
		}
	}

	private int mask(int x) {
		return 1 << x;
	}

	@Override
	public void place(Piece piece) {
		place(piece.getBoard(), piece.getX(), piece.getY());
	}
{'fraction_non_alphanumeric': 0.17158725518854137, 'fraction_numerical': 0.008184741303712365, 'mean_word_length': 3.1731707317073172, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3947089', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1273, 'n_words': 405}