Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
MyCard
magicseteditor
Commits
008fbc89
Commit
008fbc89
authored
Dec 26, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added caching to filter_text script function
parent
030e948f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
src/script/functions/basic.cpp
src/script/functions/basic.cpp
+26
-3
No files found.
src/script/functions/basic.cpp
View file @
008fbc89
...
@@ -494,14 +494,37 @@ class ScriptFilterRule : public ScriptValue {
...
@@ -494,14 +494,37 @@ class ScriptFilterRule : public ScriptValue {
// Create a regular expression rule for filtering strings
// Create a regular expression rule for filtering strings
ScriptValueP
filter_rule
(
Context
&
ctx
)
{
ScriptValueP
filter_rule
(
Context
&
ctx
)
{
intrusive_ptr
<
ScriptFilterRule
>
ret
(
new
ScriptFilterRule
);
// cached?
// match
SCRIPT_PARAM_C
(
String
,
match
);
SCRIPT_PARAM_C
(
String
,
match
);
SCRIPT_PARAM_DEFAULT_N
(
String
,
_
(
"in context"
),
in_context
,
String
());
// cache
const
int
CACHE_SIZE
=
6
;
struct
CacheItem
{
String
match
,
in_context
;
intrusive_ptr
<
ScriptFilterRule
>
rule
;
};
static
CacheItem
cache
[
CACHE_SIZE
];
static
int
cache_pos
=
0
;
// find in cache?
for
(
int
i
=
0
;
i
<
CACHE_SIZE
;
++
i
)
{
if
(
cache
[
i
].
rule
&&
cache
[
i
].
match
==
match
&&
cache
[
i
].
in_context
==
in_context
)
{
return
cache
[
i
].
rule
;
}
}
// add item
cache
[
cache_pos
].
match
=
match
;
cache
[
cache_pos
].
in_context
=
in_context
;
cache
[
cache_pos
].
rule
=
intrusive_ptr
<
ScriptFilterRule
>
(
new
ScriptFilterRule
);
intrusive_ptr
<
ScriptFilterRule
>&
ret
=
cache
[
cache_pos
].
rule
;
cache_pos
=
(
cache_pos
+
1
)
%
CACHE_SIZE
;
// match
if
(
!
ret
->
regex
.
Compile
(
match
,
wxRE_ADVANCED
))
{
if
(
!
ret
->
regex
.
Compile
(
match
,
wxRE_ADVANCED
))
{
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
match
+
_
(
"'"
));
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
match
+
_
(
"'"
));
}
}
// in_context
// in_context
SCRIPT_OPTIONAL_PARAM_N
(
String
,
_
(
"in context"
),
in_context
)
{
if
(
!
in_context
.
empty
()
)
{
if
(
!
ret
->
context
.
Compile
(
in_context
,
wxRE_ADVANCED
))
{
if
(
!
ret
->
context
.
Compile
(
in_context
,
wxRE_ADVANCED
))
{
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
in_context
+
_
(
"'"
));
throw
ScriptError
(
_
(
"Error while compiling regular expression: '"
)
+
in_context
+
_
(
"'"
));
}
}
...
...
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