<commit_before>#include "fitz.h"

fz_obj *
fz_newarray(int initialcap)
{
	fz_obj *obj;
	int i;

	obj = fz_malloc(sizeof(fz_obj));
	obj->refs = 1;
	obj->kind = FZ_ARRAY;

	obj->u.a.len = 0;
	obj->u.a.cap = initialcap > 1 ? initialcap : 6;

	obj->u.a.items = fz_calloc(obj->u.a.cap, sizeof(fz_obj*));
	for (i = 0; i < obj->u.a.cap; i++)
		obj->u.a.items[i] = nil;

	return obj;
}

fz_obj *
fz_copyarray(fz_obj *obj)
{
	fz_obj *new;
	int i;

	if (fz_isindirect(obj) || !fz_isarray(obj))
		fz_warn("assert: not an array (%s)", fz_objkindstr(obj));

	new = fz_newarray(fz_arraylen(obj));

	for (i = 0; i < fz_arraylen(obj); i++)
	{
		fz_arraypush(new, fz_arrayget(obj, i));
	}

	return new;
}

int
fz_arraylen(fz_obj *obj)
{
	obj = fz_resolveindirect(obj);
	if (!fz_isarray(obj))
		return 0;
	return obj->u.a.len;
}

fz_obj *
fz_arrayget(fz_obj *obj, int i)
{
	obj = fz_resolveindirect(obj);

	if (!fz_isarray(obj))
		return nil;

	if (i < 0 || i >= obj->u.a.len)
		return nil;

	return obj->u.a.items[i];
}

void<commit_msg>Cleanups in fz_copyarray and fz_copydict.<commit_after>#include "fitz.h"

fz_obj *
fz_newarray(int initialcap)
{
	fz_obj *obj;
	int i;

	obj = fz_malloc(sizeof(fz_obj));
	obj->refs = 1;
	obj->kind = FZ_ARRAY;

	obj->u.a.len = 0;
	obj->u.a.cap = initialcap > 1 ? initialcap : 6;

	obj->u.a.items = fz_calloc(obj->u.a.cap, sizeof(fz_obj*));
	for (i = 0; i < obj->u.a.cap; i++)
		obj->u.a.items[i] = nil;

	return obj;
}

fz_obj *
fz_copyarray(fz_obj *obj)
{
	fz_obj *new;
	int i;

	if (fz_isindirect(obj) || !fz_isarray(obj))
		fz_warn("assert: not an array (%s)", fz_objkindstr(obj));

	new = fz_newarray(fz_arraylen(obj));
	for (i = 0; i < fz_arraylen(obj); i++)
		fz_arraypush(new, fz_arrayget(obj, i));

	return new;
}

int
fz_arraylen(fz_obj *obj)
{
	obj = fz_resolveindirect(obj);
	if (!fz_isarray(obj))
		return 0;
	return obj->u.a.len;
}

fz_obj *
fz_arrayget(fz_obj *obj, int i)
{
	obj = fz_resolveindirect(obj);

	if (!fz_isarray(obj))
		return nil;

	if (i < 0 || i >= obj->u.a.len)
		return nil;

	return obj->u.a.items[i];
}

void
{'fraction_non_alphanumeric': 0.18680252304706454, 'fraction_numerical': 0.0077632217370208634, 'mean_word_length': 3.8517647058823528, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '7438999', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1017, 'n_words': 195}