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
a476d711
Unverified
Commit
a476d711
authored
Apr 24, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support `presym` in `symbol.c`.
parent
1e156974
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
2 deletions
+46
-2
src/symbol.c
src/symbol.c
+46
-2
No files found.
src/symbol.c
View file @
a476d711
...
...
@@ -12,6 +12,36 @@
#include <mruby/dump.h>
#include <mruby/class.h>
#undef MRB_PRESYM_MAX
#define MRB_PRESYM_CSYM(sym, num) #sym,
#define MRB_PRESYM_SYM(sym, num) #sym,
static
const
char
*
presym_table
[]
=
{
#include <../build/presym.inc>
NULL
};
static
mrb_sym
presym_find
(
const
char
*
name
)
{
/* use linear search for now */
/* binary search should work better */
int
i
;
for
(
i
=
0
;
presym_table
[
i
];
i
++
)
{
if
(
strcmp
(
presym_table
[
i
],
name
)
==
0
)
return
i
+
1
;
}
return
0
;
}
static
const
char
*
presym_sym2name
(
mrb_sym
sym
)
{
if
(
sym
>
MRB_PRESYM_MAX
)
return
NULL
;
return
presym_table
[
sym
-
1
];
}
/* ------------------------------------------------------ */
typedef
struct
symbol_name
{
mrb_bool
lit
:
1
;
...
...
@@ -130,6 +160,11 @@ find_symbol(mrb_state *mrb, const char *name, size_t len, uint8_t *hashp)
symbol_name
*
sname
;
uint8_t
hash
;
/* presym */
if
(
strlen
(
name
)
==
len
)
{
i
=
presym_find
(
name
);
if
(
i
>
0
)
return
i
<<
SYMBOL_NORMAL_SHIFT
;
}
/* inline symbol */
i
=
sym_inline_pack
(
name
,
len
);
if
(
i
>
0
)
return
i
;
...
...
@@ -142,7 +177,7 @@ find_symbol(mrb_state *mrb, const char *name, size_t len, uint8_t *hashp)
do
{
sname
=
&
mrb
->
symtbl
[
i
];
if
(
sname
->
len
==
len
&&
memcmp
(
sname
->
name
,
name
,
len
)
==
0
)
{
return
i
<<
SYMBOL_NORMAL_SHIFT
;
return
(
i
+
MRB_PRESYM_MAX
)
<<
SYMBOL_NORMAL_SHIFT
;
}
if
(
sname
->
prev
==
0xff
)
{
i
-=
0xff
;
...
...
@@ -205,7 +240,7 @@ sym_intern(mrb_state *mrb, const char *name, size_t len, mrb_bool lit)
}
mrb
->
symhash
[
hash
]
=
mrb
->
symidx
=
sym
;
return
sym
<<
SYMBOL_NORMAL_SHIFT
;
return
(
sym
+
MRB_PRESYM_MAX
)
<<
SYMBOL_NORMAL_SHIFT
;
}
MRB_API
mrb_sym
...
...
@@ -261,6 +296,15 @@ sym2name_len(mrb_state *mrb, mrb_sym sym, char *buf, mrb_int *lenp)
if
(
SYMBOL_INLINE_P
(
sym
))
return
sym_inline_unpack
(
sym
,
buf
,
lenp
);
sym
>>=
SYMBOL_NORMAL_SHIFT
;
{
const
char
*
name
=
presym_sym2name
(
sym
);
if
(
name
)
{
if
(
lenp
)
*
lenp
=
strlen
(
name
);
return
name
;
}
}
sym
-=
MRB_PRESYM_MAX
;
if
(
sym
==
0
||
mrb
->
symidx
<
sym
)
{
if
(
lenp
)
*
lenp
=
0
;
return
NULL
;
...
...
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