<commit_before>/*
 *  OUTPUT DRAWING FUNCTIONS
 */

/* drawQRToCanvas
 * draws a QR code to a canvas
 * @arg qr - qr code object that is ready to be drawn (i.e. has had drawSymbol
 * called)
 * @arg canvas - canvas object to draw to. this object will be resized based on scale.
 * @arg scale - OPTIONAL drawing scale. each module will be scale x scale pixels
 * in size. (default: 1)
 */
function drawQRToCanvas(qr, canvas, scale) {
	if (typeof canvas.getContext === 'undefined') {
		return;
	}
	
	if (typeof scale === 'undefined') {
		scale = 1;
	}
	
	/* set canvas size, border */
	var canvasSize = qr.dim * scale + 8 * scale 
	canvas.style.width = canvas.style.height = canvasSize.toString() + 'px';
	canvas.setAttribute('width', canvasSize.toString() + 'px');
	canvas.setAttribute('height', canvasSize.toString() + 'px');
	
	/* create canvas context, clear canvas */
	var ctx = canvas.getContext("2d");
	ctx.fillStyle = '#ffffff';
	ctx.fillRect(0, 0, canvasSize, canvasSize);
	ctx.fillStyle = '#000000';
	
	/* iterate over data and fill into canvas */
	for (var y = 0; y < qr.dim; y++) {
		for (var x = 0; x < qr.dim; x++) {
			var k = qr.getBit(x,y);
			if (k === true) {
				ctx.fillRect((x + 4) * scale, (y + 4) * scale, scale, scale);
			}
		}
	}
}

/* drawQRToDiv
 * draws a QR code to a  div
 * @arg qr - qr code object that is ready to be drawn (i.e. has had drawSymbol
 * called)
 * @arg div - div object to draw to. this object may have its container
 * properties altered. all contents will be destroyed.
 * @arg scale - OPTIONAL drawing scale. each module will be scale x scale pixels
 * in size. (default: 1)
 */
function drawQRToDiv(qr, div, scale) {
	/* remove all child objects */
	while (div.firstChild) {
		div.removeChild(div.firstChild);	
	}
	<commit_msg>Canvas drawing optimization<commit_after>/*
 *  OUTPUT DRAWING FUNCTIONS
 */

/* drawQRToCanvas
 * draws a QR code to a canvas
 * @arg qr - qr code object that is ready to be drawn (i.e. has had drawSymbol
 * called)
 * @arg canvas - canvas object to draw to. this object will be resized based on scale.
 * @arg scale - OPTIONAL drawing scale. each module will be scale x scale pixels
 * in size. (default: 1)
 */
function drawQRToCanvas(qr, canvas, scale) {
	if (typeof canvas.getContext === 'undefined') {
		return;
	}
	
	if (typeof scale === 'undefined') {
		scale = 1;
	}
	
	/* set canvas size, border */
	var canvasSize = qr.dim * scale + 8 * scale 
	canvas.style.width = canvas.style.height = canvasSize.toString() + 'px';
	canvas.setAttribute('width', canvasSize.toString() + 'px');
	canvas.setAttribute('height', canvasSize.toString() + 'px');
	
	/* create canvas context, clear canvas */
	var ctx = canvas.getContext("2d");
	ctx.fillStyle = '#ffffff';
	ctx.fillRect(0, 0, canvasSize, canvasSize);
	ctx.fillStyle = '#000000';
	
	ctx.beginPath();
	/* iterate over data and fill into canvas */
	for (var y = 0; y < qr.dim; y++) {
		for (var x = 0; x < qr.dim; x++) {
			var k = qr.getBit(x,y);
			if (k === true) {
				ctx.rect((x + 4) * scale, (y + 4) * scale, scale, scale);
			}
		}
	}
	ctx.fill();
}

/* drawQRToDiv
 * draws a QR code to a  div
 * @arg qr - qr code object that is ready to be drawn (i.e. has had drawSymbol
 * called)
 * @arg div - div object to draw to. this object may have its container
 * properties altered. all contents will be destroyed.
 * @arg scale - OPTIONAL drawing scale. each module will be scale x scale pixels
 * in size. (default: 1)
 */
function drawQRToDiv(qr, div, scale) {
	/* remove all child objects */
	while (div.firstChild) {
		div.removeChild(div.firstChild);	
	}
	
{'fraction_non_alphanumeric': 0.13844870725604672, 'fraction_numerical': 0.009452321378926884, 'mean_word_length': 3.227967097532315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4116707', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1187, 'n_words': 440}