mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
ctreemanifest: use cstores directly
Summary: Previously treemanifest always called back to Python to fetch the tree content for a given key. This patch let's us call directly in to the cstore without going through Python, when possible. Test Plan: I manually tested this by modifying the treemanifest extension to pass a uniondatapackstore to the ctreemanifest constructor, then used the debugger to ensure this code path was correct. I still need to add a test though. Reviewers: #mercurial, simonfar Reviewed By: simonfar Subscribers: simonfar, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4571442 Signature: t1:4571442:1487847314:0d578351354ee4da34b5032c01720bdedf0d185d
This commit is contained in:
parent
a79aa29030
commit
b95f6fde55
@ -18,6 +18,8 @@
|
||||
#include "manifest.h"
|
||||
#include "pythonutil.h"
|
||||
#include "treemanifest.h"
|
||||
#include "../cstore/uniondatapackstore.h"
|
||||
#include "../cstore/py-structs.h"
|
||||
|
||||
#define FILENAME_BUFFER_SIZE 16348
|
||||
#define FLAG_SIZE 1
|
||||
@ -429,21 +431,33 @@ static void treemanifest_dealloc(py_treemanifest *self) {
|
||||
* Initializes the contents of a treemanifest
|
||||
*/
|
||||
static int treemanifest_init(py_treemanifest *self, PyObject *args) {
|
||||
PyObject *store;
|
||||
PyObject *pystore;
|
||||
char *node = NULL;
|
||||
Py_ssize_t nodelen;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|s#", &store, &node, &nodelen)) {
|
||||
if (!PyArg_ParseTuple(args, "O|s#", &pystore, &node, &nodelen)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(store);
|
||||
PythonObj storeObj = PythonObj(store);
|
||||
Py_INCREF(pystore);
|
||||
PythonObj storeObj = PythonObj(pystore);
|
||||
|
||||
PythonObj cstoreModule = PyImport_ImportModule("cstore");
|
||||
PythonObj unionStoreType = cstoreModule.getattr("uniondatapackstore");
|
||||
|
||||
// If it's a cstore, we'll use it directly instead of through python.
|
||||
std::shared_ptr<Store> store;
|
||||
int isinstance = PyObject_IsInstance((PyObject*)storeObj, (PyObject*)unionStoreType);
|
||||
if (isinstance == 1) {
|
||||
store = ((py_uniondatapackstore*)(PyObject*)storeObj)->uniondatapackstore;
|
||||
}
|
||||
|
||||
// We have to manually call the member constructor, since the provided 'self'
|
||||
// is just zerod out memory.
|
||||
try {
|
||||
std::shared_ptr<Store> store = std::make_shared<PythonStore>(storeObj);
|
||||
if (!store) {
|
||||
store = std::make_shared<PythonStore>(storeObj);
|
||||
}
|
||||
if (node != NULL) {
|
||||
new(&self->tm) treemanifest(store, std::string(node, (size_t) nodelen));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user