<commit_before>json_writer/var/use_cache = 0
json_writer/proc/WriteObject(list/L)
	if(use_cache && L["__json_cache"])
		return L["__json_cache"]

	. = "{"
	var/i = 1
	for(var/k in L)
		var/val = L[k]
		. += {"\"[k]\":[write(val)]"}
		if(i++ < L.len)
			. += ","
	. += "}"

json_writer/proc/write(val)
	if(isnum(val))
		return num2text(val)
	else if(isnull(val))
		return "null"
	else if(istype(val, /list))
		if(is_associative(val))
			return WriteObject(val)
		else
			return write_array(val)
	else
		. += write_string("[val]")

json_writer/proc/write_array(list/L)
	. = "\["
	for(var/i = 1 to L.len)
		. += write(L[i])
		if(i < L.len)
			. += ","
	. += "]"

json_writer/proc/write_string(txt)
	var/static/list/json_escape = list("\\" = "\\\\", "\"" = "\\\"", "\n" = "\\n")
	for(var/targ in json_escape)
		var/start = 1<commit_msg>Makes json writer use 90% less string tree operations<commit_after>json_writer/var/use_cache = 0
json_writer/proc/WriteObject(list/L)
	if(use_cache && L["__json_cache"])
		return L["__json_cache"]
	
	. = ""
	for(var/k in L)
		. += text("\"[]\":[][]", k, write(L[k]), (i++ < L.len ? "," : ""))
	. = text([][][], "{", ., "}")
	

json_writer/proc/write(val)
	if(isnum(val))
		return num2text(val)
	else if(isnull(val))
		return "null"
	else if(istype(val, /list))
		if(is_associative(val))
			return WriteObject(val)
		else
			return write_array(val)
	else
		. += write_string("[val]")

json_writer/proc/write_array(list/L)
	return "\[[list2text(L, ",")]]"

json_writer/proc/write_string(txt)
	var/static/list/json_escape = list("\\" = "\\\\", "\"" = "\\\"", "\n" = "\\n")
	for(var/targ in json_escape)
		var/start = 1
{'fraction_non_alphanumeric': 0.2374013357619915, 'fraction_numerical': 0.006678809957498482, 'mean_word_length': 3.565096952908587, 'pattern_counts': {'":': 2, '<': 6, '<?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': '103963', 'n_tokens_mistral': 751, 'n_tokens_neox': 701, 'n_words': 109}