<commit_before>"use strict";

(function(){
	
	function MirroredTileEncoder() {		
	}
	
	MirroredTileEncoder.prototype = _.extend(new TileSetEncoders.BaseEncoder(), {
		getName: function() {
			return "Remove flipped/mirrored/color-reversed tiles";
		},
		
		doEncoding: function(converted, originalVideo) {
			converted.format = 'TILE_MAPVH';
			
			var convertedTileCache = {};
			function convertTile(hex) {
				if (convertedTileCache[hex]) {
					return convertedTileCache[hex];
				}
				
				var originalTile = TileSet.hexToTile(hex);
				var candidates = Util.cartesianProductOf([false, true], [false, true], [false, true]).map(function(tuple){
					var candidate = {};
					var transformedTile = Util.deepClone(originalTile);
					
					if (tuple[0]) {
						candidate.h = 1;
						transformedTile = TileSet.flipH(transformedTile);
					}
					
					if (tuple[1]) {
						candidate.v = 1;
						transformedTile = TileSet.flipV(transformedTile);
					}
					
					if (tuple[2]) {
						candidate.i = 1;
						transformedTile = TileSet.inverseColor(transformedTile);
					}
					
					candidate.hex = TileSet.tileToHex(transformedTile);
					return candidate;
				});
				
				convertedTileCache[hex] = candidates.reduce(function(a, b){ 
					return a.hex < b.hex ? a : b
				});
				return convertedTileCache[hex];
			}<commit_msg>Improved performance of convertTile()<commit_after>"use strict";

(function(){
	
	var BOOLEAN_3_BIT_COMBINATIONS = Util.cartesianProductOf([false, true], [false, true], [false, true]);
	
	function MirroredTileEncoder() {		
	}
	
	MirroredTileEncoder.prototype = _.extend(new TileSetEncoders.BaseEncoder(), {
		getName: function() {
			return "Remove flipped/mirrored/color-reversed tiles";
		},
		
		doEncoding: function(converted, originalVideo) {
			converted.format = 'TILE_MAPVH';
			
			var convertedTileCache = {};
			function convertTile(hex) {
				if (convertedTileCache[hex]) {
					return convertedTileCache[hex];
				}
				
				var originalTile = TileSet.hexToTile(hex);
				var candidates = BOOLEAN_3_BIT_COMBINATIONS.map(function(tuple){
					var candidate = {};
					var transformedTile = Util.deepClone(originalTile);
					
					if (tuple[0]) {
						candidate.h = 1;
						transformedTile = TileSet.flipH(transformedTile);
					}
					
					if (tuple[1]) {
						candidate.v = 1;
						transformedTile = TileSet.flipV(transformedTile);
					}
					
					if (tuple[2]) {
						candidate.i = 1;
						transformedTile = TileSet.inverseColor(transformedTile);
					}
					
					candidate.hex = TileSet.tileToHex(transformedTile);
					return candidate;
				});
				
				convertedTileCache[hex] = candidates.reduce(function(a, b){ 
					return a.hex < b.hex ? a : b
				});
				return convertedTileCache[hex];
			}
{'fraction_non_alphanumeric': 0.12318840579710146, 'fraction_numerical': 0.005072463768115942, 'mean_word_length': 3.0543318649045523, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4015227', 'n_tokens_mistral': 1201, 'n_tokens_neox': 852, 'n_words': 156}