Patchwork [3,of,4] parsers: add an API to create a new presized dict

login
register
mail settings
Submitter Siddharth Agarwal
Date June 16, 2015, 7:55 a.m.
Message ID <7b8f6849ec9d2e5f20d7.1434441356@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9658/
State Accepted
Headers show

Comments

Siddharth Agarwal - June 16, 2015, 7:55 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1434433290 25200
#      Mon Jun 15 22:41:30 2015 -0700
# Node ID 7b8f6849ec9d2e5f20d7f452e448ad2720e505b7
# Parent  cd4b59c9172aeeacce089ee0a4f26fbf09033d4e
parsers: add an API to create a new presized dict

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -185,6 +185,16 @@  static inline PyObject *_dict_new_presiz
 	return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
 }
 
+static PyObject *dict_new_presized(PyObject *self, PyObject *args)
+{
+	Py_ssize_t expected_size;
+
+	if (!PyArg_ParseTuple(args, "n:make_presized_dict", &expected_size))
+		return NULL;
+
+	return _dict_new_presized(expected_size);
+}
+
 static PyObject *make_file_foldmap(PyObject *self, PyObject *args)
 {
 	PyObject *dmap, *spec_obj, *normcase_fallback;
@@ -2524,6 +2534,8 @@  static PyMethodDef methods[] = {
 	{"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
 	{"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"},
 	{"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"},
+	{"dict_new_presized", dict_new_presized, METH_VARARGS,
+	 "construct a dict with an expected size\n"},
 	{"make_file_foldmap", make_file_foldmap, METH_VARARGS,
 	 "make file foldmap\n"},
 	{"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},