Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
5930a6eb
Commit
5930a6eb
authored
Dec 08, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Dec 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3328 from shugo/hash-dup-default_proc
Copy default_proc by Hash#dup.
parents
edf26d40
338e0ff5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
src/hash.c
src/hash.c
+13
-1
test/t/hash.rb
test/t/hash.rb
+4
-0
No files found.
src/hash.c
View file @
5930a6eb
...
@@ -225,6 +225,7 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
...
@@ -225,6 +225,7 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
struct
RHash
*
ret
;
struct
RHash
*
ret
;
khash_t
(
ht
)
*
h
,
*
ret_h
;
khash_t
(
ht
)
*
h
,
*
ret_h
;
khiter_t
k
,
ret_k
;
khiter_t
k
,
ret_k
;
mrb_value
ifnone
,
vret
;
h
=
RHASH_TBL
(
hash
);
h
=
RHASH_TBL
(
hash
);
ret
=
(
struct
RHash
*
)
mrb_obj_alloc
(
mrb
,
MRB_TT_HASH
,
mrb
->
hash_class
);
ret
=
(
struct
RHash
*
)
mrb_obj_alloc
(
mrb
,
MRB_TT_HASH
,
mrb
->
hash_class
);
...
@@ -243,7 +244,18 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
...
@@ -243,7 +244,18 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
}
}
}
}
return
mrb_obj_value
(
ret
);
if
(
MRB_RHASH_DEFAULT_P
(
hash
))
{
ret
->
flags
|=
MRB_HASH_DEFAULT
;
}
if
(
MRB_RHASH_PROCDEFAULT_P
(
hash
))
{
ret
->
flags
|=
MRB_HASH_PROC_DEFAULT
;
}
vret
=
mrb_obj_value
(
ret
);
ifnone
=
RHASH_IFNONE
(
hash
);
if
(
!
mrb_nil_p
(
ifnone
))
{
mrb_iv_set
(
mrb
,
vret
,
mrb_intern_lit
(
mrb
,
"ifnone"
),
ifnone
);
}
return
vret
;
}
}
MRB_API
mrb_value
MRB_API
mrb_value
...
...
test/t/hash.rb
View file @
5930a6eb
...
@@ -44,6 +44,10 @@ assert('Hash#dup') do
...
@@ -44,6 +44,10 @@ assert('Hash#dup') do
b
=
a
.
dup
b
=
a
.
dup
a
[
'a'
]
=
2
a
[
'a'
]
=
2
assert_equal
({
'a'
=>
1
},
b
)
assert_equal
({
'a'
=>
1
},
b
)
c
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
k
.
upcase
}
d
=
c
.
dup
assert_equal
(
"FOO"
,
d
[
"foo"
])
end
end
assert
(
'Hash#default'
,
'15.2.13.4.5'
)
do
assert
(
'Hash#default'
,
'15.2.13.4.5'
)
do
...
...
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