Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
2e55491b
Commit
2e55491b
authored
Jan 06, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use cpython dictview types and create separate types for the different dict iter types
parent
fcbfaa78
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
137 deletions
+98
-137
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-0
from_cpython/Include/dictobject.h
from_cpython/Include/dictobject.h
+2
-7
from_cpython/Objects/dictobject.c
from_cpython/Objects/dictobject.c
+24
-6
src/runtime/dict.cpp
src/runtime/dict.cpp
+61
-72
src/runtime/dict.h
src/runtime/dict.h
+1
-21
src/runtime/inline/dict.cpp
src/runtime/inline/dict.cpp
+9
-31
No files found.
from_cpython/CMakeLists.txt
View file @
2e55491b
...
...
@@ -85,6 +85,7 @@ file(GLOB_RECURSE STDOBJECT_SRCS Objects
capsule.c
cobject.c
complexobject.c
dictobject.c
dictproxy.c
exceptions.c
floatobject.c
...
...
from_cpython/Include/dictobject.h
View file @
2e55491b
...
...
@@ -103,10 +103,11 @@ PyAPI_DATA(PyTypeObject) PyDict_Type;
PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
#endif
PyAPI_DATA
(
PyTypeObject
)
PyDictKeys_Type
;
PyAPI_DATA
(
PyTypeObject
)
PyDictItems_Type
;
PyAPI_DATA
(
PyTypeObject
)
PyDictValues_Type
;
#endif
PyAPI_DATA
(
PyTypeObject
*
)
dict_cls
;
#define PyDict_Type (*dict_cls)
PyAPI_DATA
(
PyTypeObject
*
)
dictiterkey_cls
;
...
...
@@ -115,12 +116,6 @@ PyAPI_DATA(PyTypeObject*) dictitervalue_cls;
#define PyDictIterValue_Type (*dictitervalue_cls)
PyAPI_DATA
(
PyTypeObject
*
)
dictiteritem_cls
;
#define PyDictIterItem_Type (*dictiteritem_cls)
PyAPI_DATA
(
PyTypeObject
*
)
dictkeys_cls
;
#define PyDictKeys_Type (*dictkeys_cls)
PyAPI_DATA
(
PyTypeObject
*
)
dictitems_cls
;
#define PyDictItems_Type (*dictitems_cls)
PyAPI_DATA
(
PyTypeObject
*
)
dictvalues_cls
;
#define PyDictValues_Type (*dictvalues_cls)
#define PyDict_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
...
...
from_cpython/Objects/dictobject.c
View file @
2e55491b
// This file is originally from CPython 2.7, with modifications for Pyston
/* Dictionary object implementation using a hash table */
...
...
@@ -9,6 +10,8 @@
#include "Python.h"
// Pyston change: we only use the view type implementation
#if 0
/* Set a key error with the specified argument, wrapping it in a
* tuple automatically so that tuple keys are not unpacked as the
...
...
@@ -2752,6 +2755,9 @@ PyTypeObject PyDictIterItem_Type = {
0
,
};
// Pyston change: we only use the view type implementation
#endif
/***********************************************/
/* View objects for keys(), items(), values(). */
/***********************************************/
...
...
@@ -2782,12 +2788,15 @@ static Py_ssize_t
dictview_len
(
dictviewobject
*
dv
)
{
Py_ssize_t
len
=
0
;
if
(
dv
->
dv_dict
!=
NULL
)
len
=
dv
->
dv_dict
->
ma_used
;
if
(
dv
->
dv_dict
!=
NULL
)
{
// Pyston change: we sue a different dict implementation
// len = dv->dv_dict->ma_used;
len
=
PyDict_Size
((
PyObject
*
)
dv
->
dv_dict
);
}
return
len
;
}
static
PyObject
*
PyObject
*
dictview_new
(
PyObject
*
dict
,
PyTypeObject
*
type
)
{
dictviewobject
*
dv
;
...
...
@@ -2932,6 +2941,9 @@ dictview_repr(dictviewobject *dv)
/*** dict_keys ***/
// Pyston change: we have our own c++ implementation of this function
PyObject
*
dictiter_new
(
PyDictObject
*
,
PyTypeObject
*
);
static
PyObject
*
dictkeys_iter
(
dictviewobject
*
dv
)
{
...
...
@@ -3058,7 +3070,9 @@ static PyMethodDef dictkeys_methods[] = {
};
PyTypeObject
PyDictKeys_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
// Pyston change:
// PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"dict_keys"
,
/* tp_name */
sizeof
(
dictviewobject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
...
...
@@ -3143,7 +3157,9 @@ static PyMethodDef dictitems_methods[] = {
};
PyTypeObject
PyDictItems_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
// Pyston change:
// PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"dict_items"
,
/* tp_name */
sizeof
(
dictviewobject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
...
...
@@ -3209,7 +3225,9 @@ static PyMethodDef dictvalues_methods[] = {
};
PyTypeObject
PyDictValues_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
// Pyston change:
// PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"dict_values"
,
/* tp_name */
sizeof
(
dictviewobject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
...
...
src/runtime/dict.cpp
View file @
2e55491b
...
...
@@ -28,10 +28,11 @@
namespace
pyston
{
BoxedClass
*
dict_iterator_cls
=
NULL
;
BoxedClass
*
dict_keys_cls
=
NULL
;
BoxedClass
*
dict_values_cls
=
NULL
;
BoxedClass
*
dict_items_cls
=
NULL
;
extern
"C"
{
BoxedClass
*
dictiterkey_cls
=
NULL
;
BoxedClass
*
dictitervalue_cls
=
NULL
;
BoxedClass
*
dictiteritem_cls
=
NULL
;
}
Box
*
dictRepr
(
BoxedDict
*
self
)
{
std
::
vector
<
char
>
chars
;
...
...
@@ -148,33 +149,6 @@ extern "C" PyObject* PyDict_Items(PyObject* mp) noexcept {
return
dict_helper
(
mp
,
dictItems
);
}
Box
*
dictViewKeys
(
BoxedDict
*
self
)
{
if
(
!
PyDict_Check
(
self
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewkeys' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
}
BoxedDictView
*
rtn
=
new
(
dict_keys_cls
)
BoxedDictView
(
self
);
return
rtn
;
}
Box
*
dictViewValues
(
BoxedDict
*
self
)
{
if
(
!
PyDict_Check
(
self
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewvalues' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
}
BoxedDictView
*
rtn
=
new
(
dict_values_cls
)
BoxedDictView
(
self
);
return
rtn
;
}
Box
*
dictViewItems
(
BoxedDict
*
self
)
{
if
(
!
PyDict_Check
(
self
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewitems' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
}
BoxedDictView
*
rtn
=
new
(
dict_items_cls
)
BoxedDictView
(
self
);
return
rtn
;
}
// Analoguous to CPython's, used for sq_ slots.
static
Py_ssize_t
dict_length
(
PyDictObject
*
mp
)
{
return
((
BoxedDict
*
)
mp
)
->
d
.
size
();
...
...
@@ -747,21 +721,12 @@ void BoxedDict::gcHandler(GCVisitor* v, Box* b) {
}
void
BoxedDictIterator
::
gcHandler
(
GCVisitor
*
v
,
Box
*
b
)
{
assert
(
b
->
cls
==
dict_iterator_cls
);
Box
::
gcHandler
(
v
,
b
);
BoxedDictIterator
*
it
=
static_cast
<
BoxedDictIterator
*>
(
b
);
v
->
visit
(
&
it
->
d
);
}
void
BoxedDictView
::
gcHandler
(
GCVisitor
*
v
,
Box
*
b
)
{
assert
(
b
->
cls
==
dict_items_cls
||
b
->
cls
==
dict_values_cls
||
b
->
cls
==
dict_keys_cls
);
Box
::
gcHandler
(
v
,
b
);
BoxedDictView
*
view
=
static_cast
<
BoxedDictView
*>
(
b
);
v
->
visit
(
&
view
->
d
);
}
static
int
dict_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
noexcept
{
assert
(
PyDict_Check
(
self
));
try
{
...
...
@@ -788,24 +753,49 @@ void BoxedDict::dealloc(Box* b) noexcept {
static_cast
<
BoxedDict
*>
(
b
)
->
d
.
freeAllMemory
();
}
// We use cpythons dictview implementation from dictobject.c
extern
"C"
PyObject
*
dictview_new
(
PyObject
*
dict
,
PyTypeObject
*
type
)
noexcept
;
Box
*
dictViewKeys
(
BoxedDict
*
d
)
{
Box
*
rtn
=
dictview_new
(
d
,
&
PyDictKeys_Type
);
if
(
!
rtn
)
throwCAPIException
();
return
rtn
;
}
Box
*
dictViewValues
(
BoxedDict
*
d
)
{
Box
*
rtn
=
dictview_new
(
d
,
&
PyDictValues_Type
);
if
(
!
rtn
)
throwCAPIException
();
return
rtn
;
}
Box
*
dictViewItems
(
BoxedDict
*
d
)
{
Box
*
rtn
=
dictview_new
(
d
,
&
PyDictItems_Type
);
if
(
!
rtn
)
throwCAPIException
();
return
rtn
;
}
// This function gets called from dictobject.c
extern
"C"
PyObject
*
dictiter_new
(
PyDictObject
*
dict
,
PyTypeObject
*
iter_type
)
noexcept
{
return
new
(
iter_type
)
BoxedDictIterator
((
BoxedDict
*
)
dict
);
}
void
setupDict
()
{
static
PyMappingMethods
dict_as_mapping
;
dict_cls
->
tp_as_mapping
=
&
dict_as_mapping
;
static
PySequenceMethods
dict_as_sequence
;
dict_cls
->
tp_as_sequence
=
&
dict_as_sequence
;
dict_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictIterator
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-itemiterator"
);
dict_keys_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictView
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_keys"
);
dict_values_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictView
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_values"
);
dict_items_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictView
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_items"
);
dictiterkey_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictIterator
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-keyiterator"
);
dictitervalue_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictIterator
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-valueiterator"
);
dictiteritem_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
&
BoxedDictIterator
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-itemiterator"
);
dict
_iterator_cls
->
instances_are_nonzero
=
dict_keys
_cls
->
instances_are_nonzero
=
dict
_values_cls
->
instances_are_nonzero
=
dict_items
_cls
->
instances_are_nonzero
=
true
;
dict
iterkey_cls
->
instances_are_nonzero
=
dictitervalue
_cls
->
instances_are_nonzero
=
dict
iteritem
_cls
->
instances_are_nonzero
=
true
;
dict_cls
->
tp_dealloc
=
&
BoxedDict
::
dealloc
;
dict_cls
->
has_safe_tp_dealloc
=
true
;
...
...
@@ -819,7 +809,7 @@ void setupDict() {
dict_cls
->
giveAttr
(
"__ne__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictNe
,
UNKNOWN
,
2
)));
dict_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterKeys
,
typeFromClass
(
dict
_iterator
_cls
),
1
)));
typeFromClass
(
dict
iterkey
_cls
),
1
)));
dict_cls
->
giveAttr
(
"update"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictUpdate
,
NONE
,
1
,
true
,
true
)));
...
...
@@ -829,11 +819,11 @@ void setupDict() {
dict_cls
->
giveAttr
(
"has_key"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictContains
,
BOXED_BOOL
,
2
)));
dict_cls
->
giveAttr
(
"items"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictItems
,
LIST
,
1
)));
dict_cls
->
giveAttr
(
"iteritems"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterItems
,
typeFromClass
(
dict
_iterator
_cls
),
1
)));
typeFromClass
(
dict
iteritem
_cls
),
1
)));
dict_cls
->
giveAttr
(
"values"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictValues
,
LIST
,
1
)));
dict_cls
->
giveAttr
(
"itervalues"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterValues
,
typeFromClass
(
dict
_iterator
_cls
),
1
)));
typeFromClass
(
dict
itervalue
_cls
),
1
)));
dict_cls
->
giveAttr
(
"keys"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictKeys
,
LIST
,
1
)));
dict_cls
->
giveAttr
(
"iterkeys"
,
dict_cls
->
getattr
(
internStringMortal
(
"__iter__"
)));
...
...
@@ -868,15 +858,20 @@ void setupDict() {
dict_cls
->
freeze
();
FunctionMetadata
*
hasnext
=
FunctionMetadata
::
create
((
void
*
)
dictIterHasnextUnboxed
,
BOOL
,
1
);
hasnext
->
addVersion
((
void
*
)
dictIterHasnext
,
BOXED_BOOL
);
dict_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
hasnext
));
dict_iterator_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
(
(
void
*
)
dictIterIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterNext
,
UNKNOWN
,
1
)));
dict_iterator_cls
->
freeze
();
dict_iterator_cls
->
tp_iter
=
PyObject_SelfIter
;
dict_iterator_cls
->
tp_iternext
=
dictiter_next
;
// create the dictonary iterator types
for
(
BoxedClass
*
iter_type
:
{
dictiterkey_cls
,
dictitervalue_cls
,
dictiteritem_cls
})
{
FunctionMetadata
*
hasnext
=
FunctionMetadata
::
create
((
void
*
)
dictIterHasnextUnboxed
,
BOOL
,
1
);
hasnext
->
addVersion
((
void
*
)
dictIterHasnext
,
BOXED_BOOL
);
iter_type
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
hasnext
));
iter_type
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterIter
,
typeFromClass
(
iter_type
),
1
)));
iter_type
->
giveAttr
(
"next"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictIterNext
,
UNKNOWN
,
1
)));
iter_type
->
freeze
();
iter_type
->
tp_iter
=
PyObject_SelfIter
;
iter_type
->
tp_iternext
=
dictiter_next
;
iter_type
->
tp_flags
&=
~
Py_TPFLAGS_BASETYPE
;
// subclassing is not allowed
}
// Manually set some tp_* slots *after* calling freeze() -> fixup_slot_dispatchers().
// fixup_slot_dispatchers will insert a wrapper like slot_tp_init into tp_init, which calls the python-level
...
...
@@ -899,15 +894,9 @@ void setupDict() {
dict_cls
->
tp_as_sequence
->
sq_contains
=
(
objobjproc
)
PyDict_Contains
;
dict_keys_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
(
(
void
*
)
dictViewKeysIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_keys_cls
->
freeze
();
dict_values_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
(
(
void
*
)
dictViewValuesIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_values_cls
->
freeze
();
dict_items_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
(
(
void
*
)
dictViewItemsIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_items_cls
->
freeze
();
PyType_Ready
(
&
PyDictKeys_Type
);
PyType_Ready
(
&
PyDictValues_Type
);
PyType_Ready
(
&
PyDictItems_Type
);
}
void
teardownDict
()
{
...
...
src/runtime/dict.h
View file @
2e55491b
...
...
@@ -20,23 +20,13 @@
namespace
pyston
{
extern
BoxedClass
*
dict_iterator_cls
;
extern
BoxedClass
*
dict_keys_cls
;
extern
BoxedClass
*
dict_values_cls
;
extern
BoxedClass
*
dict_items_cls
;
class
BoxedDictIterator
:
public
Box
{
public:
enum
IteratorType
{
KeyIterator
,
ValueIterator
,
ItemIterator
};
BoxedDict
*
d
;
BoxedDict
::
DictMap
::
iterator
it
;
const
BoxedDict
::
DictMap
::
iterator
itEnd
;
const
IteratorType
type
;
BoxedDictIterator
(
BoxedDict
*
d
,
IteratorType
type
);
DEFAULT_CLASS
(
dict_iterator_cls
);
BoxedDictIterator
(
BoxedDict
*
d
);
static
void
gcHandler
(
GCVisitor
*
v
,
Box
*
self
);
};
...
...
@@ -53,17 +43,7 @@ llvm_compat_bool dictIterHasnextUnboxed(Box* self);
Box
*
dictiter_next
(
Box
*
self
)
noexcept
;
Box
*
dictIterNext
(
Box
*
self
);
class
BoxedDictView
:
public
Box
{
public:
BoxedDict
*
d
;
BoxedDictView
(
BoxedDict
*
d
);
static
void
gcHandler
(
GCVisitor
*
v
,
Box
*
self
);
};
Box
*
dictViewKeysIter
(
Box
*
self
);
Box
*
dictViewValuesIter
(
Box
*
self
);
Box
*
dictViewItemsIter
(
Box
*
self
);
void
dictMerge
(
BoxedDict
*
self
,
Box
*
other
);
Box
*
dictUpdate
(
BoxedDict
*
self
,
BoxedTuple
*
args
,
BoxedDict
*
kwargs
);
}
...
...
src/runtime/inline/dict.cpp
View file @
2e55491b
...
...
@@ -19,14 +19,13 @@
namespace
pyston
{
BoxedDictIterator
::
BoxedDictIterator
(
BoxedDict
*
d
,
IteratorType
type
)
:
d
(
d
),
it
(
d
->
d
.
begin
()),
itEnd
(
d
->
d
.
end
()),
type
(
type
)
{
BoxedDictIterator
::
BoxedDictIterator
(
BoxedDict
*
d
)
:
d
(
d
),
it
(
d
->
d
.
begin
()),
itEnd
(
d
->
d
.
end
())
{
}
Box
*
dict_iter
(
Box
*
s
)
noexcept
{
assert
(
PyDict_Check
(
s
));
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
KeyIterator
);
return
new
(
&
PyDictIterKey_Type
)
BoxedDictIterator
(
self
);
}
Box
*
dictIterKeys
(
Box
*
s
)
{
...
...
@@ -36,13 +35,13 @@ Box* dictIterKeys(Box* s) {
Box
*
dictIterValues
(
Box
*
s
)
{
assert
(
PyDict_Check
(
s
));
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
ValueIterator
);
return
new
(
&
PyDictIterValue_Type
)
BoxedDictIterator
(
self
);
}
Box
*
dictIterItems
(
Box
*
s
)
{
assert
(
PyDict_Check
(
s
));
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
ItemIterator
);
return
new
(
&
PyDictIterItem_Type
)
BoxedDictIterator
(
self
);
}
Box
*
dictIterIter
(
Box
*
s
)
{
...
...
@@ -50,7 +49,6 @@ Box* dictIterIter(Box* s) {
}
llvm_compat_bool
dictIterHasnextUnboxed
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_iterator_cls
);
BoxedDictIterator
*
self
=
static_cast
<
BoxedDictIterator
*>
(
s
);
return
self
->
it
!=
self
->
itEnd
;
...
...
@@ -61,19 +59,20 @@ Box* dictIterHasnext(Box* s) {
}
Box
*
dictiter_next
(
Box
*
s
)
noexcept
{
assert
(
s
->
cls
==
dict_iterator_cls
);
BoxedDictIterator
*
self
=
static_cast
<
BoxedDictIterator
*>
(
s
);
if
(
self
->
it
==
self
->
itEnd
)
return
NULL
;
Box
*
rtn
=
nullptr
;
if
(
self
->
type
==
BoxedDictIterator
::
KeyIterator
)
{
if
(
self
->
cls
==
&
PyDictIterKey_Type
)
{
rtn
=
self
->
it
->
first
.
value
;
}
else
if
(
self
->
type
==
BoxedDictIterator
::
ValueIterator
)
{
}
else
if
(
self
->
cls
==
&
PyDictIterValue_Type
)
{
rtn
=
self
->
it
->
second
;
}
else
if
(
self
->
type
==
BoxedDictIterator
::
ItemIterator
)
{
}
else
if
(
self
->
cls
==
&
PyDictIterItem_Type
)
{
rtn
=
BoxedTuple
::
create
({
self
->
it
->
first
.
value
,
self
->
it
->
second
});
}
else
{
RELEASE_ASSERT
(
0
,
""
);
}
++
self
->
it
;
return
rtn
;
...
...
@@ -85,25 +84,4 @@ Box* dictIterNext(Box* s) {
raiseExcHelper
(
StopIteration
,
""
);
return
rtn
;
}
BoxedDictView
::
BoxedDictView
(
BoxedDict
*
d
)
:
d
(
d
)
{
}
Box
*
dictViewKeysIter
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_keys_cls
);
BoxedDictView
*
self
=
static_cast
<
BoxedDictView
*>
(
s
);
return
dictIterKeys
(
self
->
d
);
}
Box
*
dictViewValuesIter
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_values_cls
);
BoxedDictView
*
self
=
static_cast
<
BoxedDictView
*>
(
s
);
return
dictIterValues
(
self
->
d
);
}
Box
*
dictViewItemsIter
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_items_cls
);
BoxedDictView
*
self
=
static_cast
<
BoxedDictView
*>
(
s
);
return
dictIterItems
(
self
->
d
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment