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
25e4ec3f
Commit
25e4ec3f
authored
Feb 04, 2016
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache UTF8 status for utf8_strlen(); ref #980
parent
5e514c91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
include/mruby/string.h
include/mruby/string.h
+4
-3
src/string.c
src/string.c
+7
-0
No files found.
include/mruby/string.h
View file @
25e4ec3f
...
...
@@ -81,9 +81,10 @@ mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_SHARED 1
#define MRB_STR_NOFREE 2
#define MRB_STR_FROZEN 4
#define MRB_STR_EMBED 8
#define MRB_STR_EMBED_LEN_MASK 0x1f0
#define MRB_STR_EMBED_LEN_SHIFT 4
#define MRB_STR_NO_UTF 8
#define MRB_STR_EMBED 16
#define MRB_STR_EMBED_LEN_MASK 0x3e0
#define MRB_STR_EMBED_LEN_SHIFT 5
void
mrb_gc_free_str
(
mrb_state
*
,
struct
RString
*
);
MRB_API
void
mrb_str_modify
(
mrb_state
*
,
struct
RString
*
);
...
...
src/string.c
View file @
25e4ec3f
...
...
@@ -273,11 +273,17 @@ utf8_strlen(mrb_value str, mrb_int len)
mrb_int
total
=
0
;
char
*
p
=
RSTRING_PTR
(
str
);
char
*
e
=
p
;
if
(
RSTRING
(
str
)
->
flags
&
MRB_STR_NO_UTF
)
{
return
RSTRING_LEN
(
str
);
}
e
+=
len
<
0
?
RSTRING_LEN
(
str
)
:
len
;
while
(
p
<
e
)
{
p
+=
utf8len
(
p
,
e
);
total
++
;
}
if
(
RSTRING_LEN
(
str
)
==
total
)
{
RSTRING
(
str
)
->
flags
|=
MRB_STR_NO_UTF
;
}
return
total
;
}
...
...
@@ -652,6 +658,7 @@ MRB_API void
mrb_str_modify
(
mrb_state
*
mrb
,
struct
RString
*
s
)
{
check_frozen
(
mrb
,
s
);
s
->
flags
&=
~
MRB_STR_NO_UTF
;
if
(
RSTR_SHARED_P
(
s
))
{
mrb_shared_string
*
shared
=
s
->
as
.
heap
.
aux
.
shared
;
...
...
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