<commit_before>/*
 * L.Mixin.Events is used to add custom events functionality to Leaflet classes.
 */

var eventsKey = '_leaflet_events';

L.Evented = L.Class.extend({

	on: function (types, fn, context) {

		// types can be a map of types/handlers
		if (typeof types === 'object') {
			for (var type in types) {
				this._on(type, types[type], fn);
			}
			return this;
		}

		// types can be a string of space-separated words
		types = L.Util.splitWords(types);

		for (var i = 0, len = types.length; i < len; i++) {
			this._on(types[i], fn, context);
		}

		return this;
	},

	// attach listener (without syntactic sugar now)
	_on: function (type, fn, context) {

		var events = this[eventsKey] = this[eventsKey] || {},
		    contextId = context && context !== this && L.stamp(context);

		if (contextId) {
			// store listeners of a particular context in a separate hash (if it has an id)
			// gives a major performance boost when removing thousands of map layers

			var fnId = L.stamp(fn),
			    indexKey = type + '_idx',
			    indexLenKey = type + '_len',
			    typeIndex = events[indexKey] = events[indexKey] || {};

			typeIndex[fnId] = typeIndex[fnId] || {};

			if (!typeIndex[fnId][contextId]) {
				typeIndex[fnId][contextId] = {fn: fn, ctx: context};

				// keep track of the number of keys in the index to quickly check if it's empty
				events[indexLenKey] = (events[indexLenKey] || 0) + 1;
			}

		} else {
			events[type] = events[type] || [];
			events[type].push({fn: fn});
		}
	},

	off: function (types, fn, context) {

		if (!types) {
			delete this[eventsKey];
			return this;
		}

		if (typeof types === 'object') {
			for (var type in types) {
				this._off(type, types[type], fn);
			}
			return this;
		}

		types = L.Util.splitWords(types);

		for (var i = 0, len = types.length; i < len; i++) {
			this._off(types[i], fn, context);
		}

		return this;
	},

	_off: function (type, fn, context) {
		var events = this[eventsKey],
		    indexKey = type + '_idx',
		    indexLenKey = type + '_len';
<commit_msg>clean up events code a bit<commit_after>/*
 * L.Mixin.Events is used to add custom events functionality to Leaflet classes.
 */

var eventsKey = '_leaflet_events';

L.Evented = L.Class.extend({

	on: function (types, fn, context) {

		// types can be a map of types/handlers
		if (typeof types === 'object') {
			for (var type in types) {
				this._on(type, types[type], fn);
			}

		} else {
			// types can be a string of space-separated words
			types = L.Util.splitWords(types);

			for (var i = 0, len = types.length; i < len; i++) {
				this._on(types[i], fn, context);
			}
		}

		return this;
	},

	off: function (types, fn, context) {

		if (!types) {
			// clear all listeners if called without arguments
			delete this[eventsKey];

		} else if (typeof types === 'object') {
			for (var type in types) {
				this._off(type, types[type], fn);
			}

		} else {
			types = L.Util.splitWords(types);

			for (var i = 0, len = types.length; i < len; i++) {
				this._off(types[i], fn, context);
			}
		}

		return this;
	},

	// attach listener (without syntactic sugar now)
	_on: function (type, fn, context) {

		var events = this[eventsKey] = this[eventsKey] || {},
		    contextId = context && context !== this && L.stamp(context);

		if (contextId) {
			// store listeners of a particular context in a separate hash (if it has an id)
			// gives a major performance boost when removing thousands of map layers

			var fnId = L.stamp(fn),
			    indexKey = type + '_idx',
			    indexLenKey = type + '_len',
			    typeIndex = events[indexKey] = events[indexKey] || {};

			typeIndex[fnId] = typeIndex[fnId] || {};

			if (!typeIndex[fnId][contextId]) {
				typeIndex[fnId][contextId] = {fn: fn, ctx: context};

				// keep track of the number of keys in the index to quickly check if it's empty
				events[indexLenKey] = (events[indexLenKey] || 0) + 1;
			}

		} else {
			events[type] = events[type] || [];
			events[type].push({fn: fn});
		}
	},

	_off: function (type, fn, context) {
		var events = this[eventsKey],
		    indexKey = type + '_idx',
		    indexLenKey = type + '_len';

{'fraction_non_alphanumeric': 0.14955303213336554, 'fraction_numerical': 0.0019328340178787146, 'mean_word_length': 2.9204545454545454, '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': '3580053', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1365, 'n_words': 441}