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
61211349
Commit
61211349
authored
Dec 22, 2014
by
asaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use DictView class instead of DictKeys / DictValues / DictItems
parent
71e9cdff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
22 deletions
+50
-22
src/runtime/dict.cpp
src/runtime/dict.cpp
+16
-6
src/runtime/dict.h
src/runtime/dict.h
+5
-13
src/runtime/inline/dict.cpp
src/runtime/inline/dict.cpp
+16
-3
test/tests/dict.py
test/tests/dict.py
+13
-0
No files found.
src/runtime/dict.cpp
View file @
61211349
...
...
@@ -91,17 +91,17 @@ Box* dictKeys(BoxedDict* self) {
}
Box
*
dictViewKeys
(
BoxedDict
*
self
)
{
BoxedDict
Keys
*
rtn
=
new
BoxedDictKeys
(
self
);
BoxedDict
View
*
rtn
=
new
BoxedDictView
(
self
,
dict_keys_cls
);
return
rtn
;
}
Box
*
dictViewValues
(
BoxedDict
*
self
)
{
BoxedDictV
alues
*
rtn
=
new
BoxedDictValues
(
self
);
BoxedDictV
iew
*
rtn
=
new
BoxedDictView
(
self
,
dict_values_cls
);
return
rtn
;
}
Box
*
dictViewItems
(
BoxedDict
*
self
)
{
BoxedDict
Items
*
rtn
=
new
BoxedDictItems
(
self
);
BoxedDict
View
*
rtn
=
new
BoxedDictView
(
self
,
dict_items_cls
);
return
rtn
;
}
...
...
@@ -441,15 +441,19 @@ BoxedClass* dict_keys_cls = NULL;
BoxedClass
*
dict_values_cls
=
NULL
;
BoxedClass
*
dict_items_cls
=
NULL
;
extern
"C"
void
dictViewGCHandler
(
GCVisitor
*
v
,
Box
*
b
)
{
boxGCHandler
(
v
,
b
);
BoxedDictIterator
*
it
=
static_cast
<
BoxedDictIterator
*>
(
b
);
v
->
visit
(
it
->
d
);
}
void
setupDict
()
{
dict_iterator_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictIteratorGCHandler
,
0
,
sizeof
(
BoxedDict
),
false
);
dict_keys_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDict
Keys
),
false
);
dict_values_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictV
alues
),
false
);
dict_items_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDict
Items
),
false
);
dict_keys_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDict
View
),
false
);
dict_values_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictV
iew
),
false
);
dict_items_cls
=
new
BoxedHeapClass
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDict
View
),
false
);
dict_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"dict"
));
dict_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictLen
,
BOXED_INT
,
1
)));
...
...
@@ -514,10 +518,16 @@ void setupDict() {
dict_iterator_cls
->
freeze
();
dict_keys_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"dictkeys"
));
dict_keys_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictViewKeysIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_keys_cls
->
freeze
();
dict_values_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"dictvalues"
));
dict_values_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictViewValuesIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_values_cls
->
freeze
();
dict_items_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"dictitems"
));
dict_items_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictViewItemsIter
,
typeFromClass
(
dict_iterator_cls
),
1
)));
dict_items_cls
->
freeze
();
}
...
...
src/runtime/dict.h
View file @
61211349
...
...
@@ -46,23 +46,15 @@ Box* dictIterHasnext(Box* self);
i1
dictIterHasnextUnboxed
(
Box
*
self
);
Box
*
dictIterNext
(
Box
*
self
);
class
BoxedDict
Keys
:
public
Box
{
class
BoxedDict
View
:
public
Box
{
public:
BoxedDict
*
d
;
BoxedDict
Keys
(
BoxedDict
*
d
);
BoxedDict
View
(
BoxedDict
*
d
,
BoxedClass
*
view_cls
);
};
class
BoxedDictValues
:
public
Box
{
public:
BoxedDict
*
d
;
BoxedDictValues
(
BoxedDict
*
d
);
};
class
BoxedDictItems
:
public
Box
{
public:
BoxedDict
*
d
;
BoxedDictItems
(
BoxedDict
*
d
);
};
Box
*
dictViewKeysIter
(
Box
*
self
);
Box
*
dictViewValuesIter
(
Box
*
self
);
Box
*
dictViewItemsIter
(
Box
*
self
);
}
...
...
src/runtime/inline/dict.cpp
View file @
61211349
...
...
@@ -72,13 +72,26 @@ Box* dictIterNext(Box* s) {
return
rtn
;
}
BoxedDictKeys
::
BoxedDictKeys
(
BoxedDict
*
d
)
:
Box
(
dict_keys_cls
),
d
(
d
)
{
BoxedDictView
::
BoxedDictView
(
BoxedDict
*
d
,
BoxedClass
*
view_cls
)
:
Box
(
view_cls
),
d
(
d
)
{
}
BoxedDictValues
::
BoxedDictValues
(
BoxedDict
*
d
)
:
Box
(
dict_values_cls
),
d
(
d
)
{
Box
*
dictViewKeysIter
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_keys_cls
);
BoxedDictView
*
self
=
static_cast
<
BoxedDictView
*>
(
s
);
return
dictIterKeys
(
self
->
d
);
}
BoxedDictItems
::
BoxedDictItems
(
BoxedDict
*
d
)
:
Box
(
dict_items_cls
),
d
(
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
);
}
}
test/tests/dict.py
View file @
61211349
...
...
@@ -194,3 +194,16 @@ d = {}
d
.
update
({
'c'
:
3
},
a
=
1
,
b
=
2
)
print
sorted
(
d
.
items
())
# viewkeys / viewvalues / viewitems
d
=
{}
print
list
(
d
.
viewkeys
())
print
list
(
d
.
viewvalues
())
print
list
(
d
.
viewitems
())
d
[
'a'
]
=
1
print
list
(
d
.
viewkeys
())
print
list
(
d
.
viewvalues
())
print
list
(
d
.
viewitems
())
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