~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_c.c

  • Committer: John Arbash Meinel
  • Date: 2009-10-07 15:48:32 UTC
  • mto: (4679.6.1 2.1-export-c-api)
  • mto: This revision was merged to the branch mainline in revision 4735.
  • Revision ID: john@arbash-meinel.com-20091007154832-lpipxg46lynh9wmr
Rename StaticTupleInterner => SimpleSet.

This is a bit more appropriate, because the internal data type is not
specialized into StaticTuple objects only. Partially because I didn't
see a specific memory/speed tradeoff to caching the hash, and
that accessing said hash was siginficantly faster than just
calling PyObject_Hash().

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "_static_tuple_c.h"
24
24
#include "_export_c_api.h"
25
 
#include "_static_tuple_interned_pyx_api.h"
 
25
#include "_simple_set_pyx_api.h"
26
26
 
27
27
#include "python-compat.h"
28
28
 
85
85
        Py_INCREF(self);
86
86
        return self;
87
87
    }
88
 
    /* StaticTupleInterner_Add returns whatever object is present at self
 
88
    /* SimpleSet_Add returns whatever object is present at self
89
89
     * or the new object if it needs to add it.
90
90
     */
91
 
    unique_key = StaticTupleInterner_Add(_interned_tuples, (PyObject *)self);
 
91
    unique_key = SimpleSet_Add(_interned_tuples, (PyObject *)self);
92
92
    if (!unique_key) {
93
93
        // Suppress any error and just return the object
94
94
        PyErr_Clear();
121
121
    if (_StaticTuple_is_interned(self)) {
122
122
        /* revive dead object temporarily for DelItem */
123
123
        // Py_REFCNT(self) = 2;
124
 
        if (StaticTupleInterner_Discard(_interned_tuples, (PyObject*)self) != 1)
 
124
        if (SimpleSet_Discard(_interned_tuples, (PyObject*)self) != 1)
125
125
            Py_FatalError("deletion of interned StaticTuple failed");
126
126
    }
127
127
    len = self->size;
591
591
     */
592
592
    (traverseproc)StaticTuple_traverse,          /* tp_traverse */
593
593
    0,                                           /* tp_clear */
594
 
    // TODO: implement richcompare, we should probably be able to compare vs an
595
 
    //       tuple, as well as versus another StaticTuples object.
596
594
    StaticTuple_richcompare,                     /* tp_richcompare */
597
595
    0,                                           /* tp_weaklistoffset */
598
 
    // We could implement this as returning tuples of keys...
 
596
    // without implementing tp_iter, Python will fall back to PySequence*
 
597
    // which seems to work ok, we may need something faster/lighter in the
 
598
    // future.
599
599
    0,                                           /* tp_iter */
600
600
    0,                                           /* tp_iternext */
601
601
    StaticTuple_methods,                         /* tp_methods */
612
612
};
613
613
 
614
614
 
615
 
static char KeyIntern_doc[] = "";
616
 
 
617
 
static PyMethodDef KeyIntern_methods[] = {
618
 
    // {"as_tuple", (PyCFunction)Keys_as_tuple, METH_NOARGS, Keys_as_tuple_doc},
619
 
    {NULL, NULL} /* sentinel */
620
 
};
621
 
 
622
 
// static PySequenceMethods KeyIntern_as_sequence = {
623
 
//     0, //(lenfunc)Keys_length,           /* sq_length */
624
 
//     0,                              /* sq_concat */
625
 
//     0,                              /* sq_repeat */
626
 
//     0, //(ssizeargfunc)Keys_item,        /* sq_item */
627
 
//     0,                              /* sq_slice */
628
 
//     0,                              /* sq_ass_item */
629
 
//     0,                              /* sq_ass_slice */
630
 
//     0,                              /* sq_contains */
631
 
// };
632
 
 
633
 
// static PyTypeObject KeyIntern_Type = {
634
 
//     PyObject_HEAD_INIT(NULL)
635
 
//     0,                                           /* ob_size */
636
 
//     "KeyIntern",                                 /* tp_name */
637
 
//     sizeof(KeyIntern) - sizeof(Key *),           /* tp_basicsize */
638
 
//     sizeof(Key *),                               /* tp_itemsize */
639
 
//     0, //(destructor)Keys_dealloc,               /* tp_dealloc */
640
 
//     0,                                           /* tp_print */
641
 
//     0,                                           /* tp_getattr */
642
 
//     0,                                           /* tp_setattr */
643
 
//     0,                                           /* tp_compare */
644
 
//     // TODO: implement repr() and possibly str()
645
 
//     0, //(reprfunc)Keys_repr,                         /* tp_repr */
646
 
//     0,                                           /* tp_as_number */
647
 
//     &KeyIntern_as_sequence,                      /* tp_as_sequence */
648
 
//     0,                                           /* tp_as_mapping */
649
 
//     0, //(hashfunc)Keys_hash,                         /* tp_hash */
650
 
//     0,                                           /* tp_call */
651
 
//     0,                                           /* tp_str */
652
 
//     PyObject_GenericGetAttr,                     /* tp_getattro */
653
 
//     0,                                           /* tp_setattro */
654
 
//     0,                                           /* tp_as_buffer */
655
 
//     Py_TPFLAGS_DEFAULT,                          /* tp_flags*/
656
 
//     0, // Keys_doc,                                    /* tp_doc */
657
 
//     /* See Key_traverse for why we have this, even though we aren't GC */
658
 
//     0, //(traverseproc)Keys_traverse,                 /* tp_traverse */
659
 
//     0,                                           /* tp_clear */
660
 
//     // TODO: implement richcompare, we should probably be able to compare vs an
661
 
//     //       tuple, as well as versus another Keys object.
662
 
//     0, //Keys_richcompare,                            /* tp_richcompare */
663
 
//     0,                                           /* tp_weaklistoffset */
664
 
//     // We could implement this as returning tuples of keys...
665
 
//     0,                                           /* tp_iter */
666
 
//     0,                                           /* tp_iternext */
667
 
//     KeyIntern_methods,                           /* tp_methods */
668
 
//     0,                                           /* tp_members */
669
 
//     0,                                           /* tp_getset */
670
 
//     0,                                           /* tp_base */
671
 
//     0,                                           /* tp_dict */
672
 
//     0,                                           /* tp_descr_get */
673
 
//     0,                                           /* tp_descr_set */
674
 
//     0,                                           /* tp_dictoffset */
675
 
//     0,                                           /* tp_init */
676
 
//     0,                                           /* tp_alloc */
677
 
//     0, //Keys_new,                                    /* tp_new */
678
 
// };
679
 
 
680
 
 
681
615
static PyMethodDef static_tuple_c_methods[] = {
682
 
//    {"unique_lcs_c", py_unique_lcs, METH_VARARGS},
683
 
//    {"recurse_matches_c", py_recurse_matches, METH_VARARGS},
684
616
    {NULL, NULL}
685
617
};
686
618
 
688
620
static void
689
621
setup_interned_tuples(PyObject *m)
690
622
{
691
 
    _interned_tuples = (PyObject *)StaticTupleInterner_New();
 
623
    _interned_tuples = (PyObject *)SimpleSet_New();
692
624
    if (_interned_tuples != NULL) {
693
625
        Py_INCREF(_interned_tuples);
694
626
        PyModule_AddObject(m, "_interned_tuples", _interned_tuples);
748
680
 
749
681
    Py_INCREF(&StaticTuple_Type);
750
682
    PyModule_AddObject(m, "StaticTuple", (PyObject *)&StaticTuple_Type);
751
 
    import_bzrlib___static_tuple_interned_pyx();
 
683
    import_bzrlib___simple_set_pyx();
752
684
    setup_interned_tuples(m);
753
685
    setup_empty_tuple(m);
754
686
    setup_c_api(m);