Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
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
kumir
kumir2
Commits
c59846ef
Commit
c59846ef
authored
Feb 05, 2021
by
Alexander A. Maly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to optimize string indexing
parent
1ad918af
Pipeline
#3039
passed with stages
in 3 minutes and 57 seconds
Changes
3
Pipelines
6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
8 deletions
+43
-8
src/kumir2-libs/vm/variant.cpp
src/kumir2-libs/vm/variant.cpp
+18
-0
src/kumir2-libs/vm/variant.hpp
src/kumir2-libs/vm/variant.hpp
+11
-0
src/kumir2-libs/vm/vm.cpp
src/kumir2-libs/vm/vm.cpp
+14
-8
No files found.
src/kumir2-libs/vm/variant.cpp
View file @
c59846ef
...
...
@@ -77,7 +77,25 @@ void Variable::setValue(const AnyValue &v)
}
const
String
&
Variable
::
toStringRef
()
const
{
static
const
String
empty
;
if
(
reference_
)
{
if
(
referenceIndeces_
[
3
]
!=
0
)
{
Kumir
::
Core
::
abort
(
Kumir
::
Core
::
fromUtf8
(
"Плохая ссылка на строку"
));
return
empty
;
}
return
reference_
->
toStringRef
();
}
if
(
baseType_
!=
VT_string
)
{
Kumir
::
Core
::
abort
(
Kumir
::
Core
::
fromUtf8
(
"Величина не строковая"
));
return
empty
;
}
return
value_
.
toStringRef
();
}
String
Variable
::
toString
()
const
...
...
src/kumir2-libs/vm/variant.hpp
View file @
c59846ef
...
...
@@ -265,6 +265,16 @@ public:
}
}
const
String
&
toStringRef
()
const
{
static
const
String
empty
;
if
(
svalue_
==
0
)
{
Kumir
::
Core
::
abort
(
Kumir
::
Core
::
fromUtf8
(
"Значение не строковое"
));
return
empty
;
}
return
*
svalue_
;
}
String
toString
()
const
{
if
(
type_
==
VT_int
)
{
...
...
@@ -701,6 +711,7 @@ public:
return
value
().
toChar
();
}
const
String
&
toStringRef
()
const
;
String
toString
()
const
;
String
toString
(
int
indeces
[
4
])
const
;
...
...
src/kumir2-libs/vm/vm.cpp
View file @
c59846ef
...
...
@@ -1272,9 +1272,10 @@ void KumirVM::do_stdcall(uint16_t alg)
}
/* алг цел длин(лит s) */
case
0x001f
:
{
const
String
x
=
valuesStack_
.
pop
().
toString
();
int
y
=
x
.
length
();
valuesStack_
.
push
(
Variable
(
y
));
const
String
&
s
=
valuesStack_
.
top
().
toStringRef
();
size_t
l
=
s
.
length
();
valuesStack_
.
pop
();
valuesStack_
.
push
(
Variable
((
int
)
l
));
break
;
}
/* алг цел код(сим ch) */
...
...
@@ -1889,13 +1890,17 @@ void KumirVM::do_specialcall(uint16_t alg)
if
(
stacksMutex_
)
{
stacksMutex_
->
lock
();
}
Variable
second
=
valuesStack_
.
pop
();
Variable
first
=
valuesStack_
.
pop
();
int
index
=
second
.
value
().
toInt
();
const
String
&
s
=
first
.
value
().
toString
();
Variable
first
=
valuesStack_
.
pop
();
//const String &s = first.value().toString();
const
String
&
s
=
first
.
toStringRef
();
error_
=
Kumir
::
Core
::
getError
();
if
(
error_
.
length
()
==
0
)
{
if
(
index
<
1
||
index
>
(
int
)
s
.
length
())
{
if
(
index
<
1
||
index
>
(
int
)
s
.
length
())
{
error_
=
Kumir
::
Core
::
fromUtf8
(
"Индекс символа больше длины строки"
);
}
else
{
Char
result
=
s
[
index
-
1
];
...
...
@@ -1903,6 +1908,7 @@ void KumirVM::do_specialcall(uint16_t alg)
valuesStack_
.
push
(
r
);
}
}
if
(
stacksMutex_
)
{
stacksMutex_
->
unlock
();
}
...
...
@@ -1942,7 +1948,7 @@ void KumirVM::do_specialcall(uint16_t alg)
Variable
first
=
valuesStack_
.
pop
();
int
start
=
second
.
value
().
toInt
();
int
end
=
third
.
value
().
toInt
();
const
String
&
s
=
first
.
value
().
toString
();
const
String
&
s
=
first
.
toStringRef
();
error_
=
Kumir
::
Core
::
getError
();
if
(
error_
.
length
()
==
0
)
{
if
(
start
<
1
||
start
>
(
int
)
s
.
length
())
{
...
...
@@ -1950,7 +1956,7 @@ void KumirVM::do_specialcall(uint16_t alg)
}
else
if
(
end
<
start
)
{
String
empty
;
valuesStack_
.
push
(
Variable
(
empty
));
}
else
if
(
end
<
1
||
end
>
(
int
)
s
.
length
())
{
}
else
if
(
end
<
1
||
end
>
(
int
)
s
.
length
())
{
error_
=
Kumir
::
Core
::
fromUtf8
(
"Правая граница вырезки за пределами строки"
);
}
else
{
String
result
=
s
.
substr
(
start
-
1
,
end
-
start
+
1
);
...
...
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