PageRenderTime 203ms CodeModel.GetById 101ms app.highlight 6ms RepoModel.GetById 95ms app.codeStats 0ms

/Util/PySmallPtrSet.cc

http://unladen-swallow.googlecode.com/
C++ | 68 lines | 53 code | 13 blank | 2 comment | 4 complexity | 40c81681ff834d8d5cc814dcead1e4f3 MD5 | raw file
 1#include "Util/PySmallPtrSet.h"
 2
 3#include "llvm/ADT/SmallPtrSet.h"
 4#include "llvm/ADT/SmallVector.h"
 5
 6
 7typedef llvm::SmallPtrSet<PyObject *, 8> PySmallPtrSet_Impl;
 8
 9typedef struct PySmallPtrSet {
10    PySmallPtrSet_Impl llvm_set;
11} PySmallPtrSet;
12
13
14// C'tors, d'tors
15PySmallPtrSet *
16PySmallPtrSet_New()
17{
18    PySmallPtrSet *set = PyMem_New(PySmallPtrSet, 1);
19    if (set == NULL)
20        return NULL;
21    new(set)PySmallPtrSet();
22
23    return set;
24}
25
26void
27PySmallPtrSet_Del(PySmallPtrSet *set)
28{
29    set->~PySmallPtrSet();
30    PyMem_Free(set);
31}
32
33int
34PySmallPtrSet_Insert(PySmallPtrSet *set, PyObject *obj)
35{
36    return set->llvm_set.insert(obj);
37}
38
39int
40PySmallPtrSet_Erase(PySmallPtrSet *set, PyObject *obj)
41{
42    return set->llvm_set.erase(obj);
43}
44
45unsigned
46PySmallPtrSet_Size(PySmallPtrSet *set)
47{
48    return set->llvm_set.size();
49}
50
51int
52PySmallPtrSet_Count(PySmallPtrSet *set, PyObject *obj)
53{
54    return set->llvm_set.count(obj);
55}
56
57void
58PySmallPtrSet_ForEach(PySmallPtrSet *set, PySmallPtrSetCallback callback,
59                      void *callback_arg)
60{
61    // Copy the original set in case the callback modifies the set.
62    llvm::SmallVector<PyObject *, 8> contents(set->llvm_set.begin(),
63                                              set->llvm_set.end());
64    for (llvm::SmallVector<PyObject *, 8>::iterator i = contents.begin(),
65            end = contents.end(); i != end; ++i) {
66        callback(*i, callback_arg);
67    }
68}