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
673d9183
Commit
673d9183
authored
Dec 25, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid copying when the original string comes with MRB_STR_NOFREE
parent
9b7b18aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
include/mruby/string.h
include/mruby/string.h
+3
-0
src/state.c
src/state.c
+13
-6
src/string.c
src/string.c
+0
-3
No files found.
include/mruby/string.h
View file @
673d9183
...
...
@@ -32,6 +32,9 @@ struct RString {
#define RSTRING_CAPA(s) (RSTRING(s)->aux.capa)
#define RSTRING_END(s) (RSTRING(s)->ptr + RSTRING(s)->len)
#define MRB_STR_SHARED 1
#define MRB_STR_NOFREE 2
void
mrb_gc_free_str
(
mrb_state
*
,
struct
RString
*
);
void
mrb_str_modify
(
mrb_state
*
,
struct
RString
*
);
mrb_value
mrb_str_literal
(
mrb_state
*
,
mrb_value
);
...
...
src/state.c
View file @
673d9183
...
...
@@ -136,7 +136,9 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
mrb_free
(
mrb
,
irep
->
iseq
);
for
(
i
=
0
;
i
<
irep
->
plen
;
i
++
)
{
if
(
mrb_type
(
irep
->
pool
[
i
])
==
MRB_TT_STRING
)
{
mrb_free
(
mrb
,
mrb_str_ptr
(
irep
->
pool
[
i
])
->
ptr
);
if
(
mrb_str_ptr
(
irep
->
pool
[
i
])
->
flags
&
MRB_STR_NOFREE
==
0
)
{
mrb_free
(
mrb
,
mrb_str_ptr
(
irep
->
pool
[
i
])
->
ptr
);
}
mrb_free
(
mrb
,
mrb_obj_ptr
(
irep
->
pool
[
i
]));
}
#ifdef MRB_WORD_BOXING
...
...
@@ -170,12 +172,17 @@ mrb_str_pool(mrb_state *mrb, mrb_value str)
len
=
s
->
len
;
ns
->
len
=
len
;
ns
->
ptr
=
(
char
*
)
mrb_malloc
(
mrb
,
(
size_t
)
len
+
1
);
if
(
s
->
ptr
)
{
memcpy
(
ns
->
ptr
,
s
->
ptr
,
len
);
if
(
s
->
flags
&
MRB_STR_NOFREE
)
{
ns
->
ptr
=
s
->
ptr
;
ns
->
flags
=
MRB_STR_NOFREE
;
}
else
{
ns
->
ptr
=
(
char
*
)
mrb_malloc
(
mrb
,
(
size_t
)
len
+
1
);
if
(
s
->
ptr
)
{
memcpy
(
ns
->
ptr
,
s
->
ptr
,
len
);
}
ns
->
ptr
[
len
]
=
'\0'
;
}
ns
->
ptr
[
len
]
=
'\0'
;
return
mrb_obj_value
(
ns
);
}
...
...
src/string.c
View file @
673d9183
...
...
@@ -30,9 +30,6 @@ typedef struct mrb_shared_string {
mrb_int
len
;
}
mrb_shared_string
;
#define MRB_STR_SHARED 1
#define MRB_STR_NOFREE 2
static
mrb_value
str_replace
(
mrb_state
*
mrb
,
struct
RString
*
s1
,
struct
RString
*
s2
);
static
mrb_value
mrb_str_subseq
(
mrb_state
*
mrb
,
mrb_value
str
,
mrb_int
beg
,
mrb_int
len
);
...
...
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