Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-and-itasks
clean-sapl
Commits
02155248
Commit
02155248
authored
Mar 07, 2016
by
Laszlo Domoszlai
Browse files
John's optimizations
parent
d6ce036a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Sapl/FastString.icl
View file @
02155248
...
...
@@ -6,48 +6,40 @@ skipChars :: !String !Int (Char -> Bool) -> Int
skipChars
line
start
f
|
start
==
size
line
=
size
line
|
f
line
.[
start
]
#!
c
=
line
.[
start
]
|
f
c
=
skipChars
line
(
start
+
1
)
f
=
start
startsWith
::
!
String
!
String
->
Bool
startsWith
start
str
|
(
size
str
)
>=
(
size
start
)
=
startsWith_
((
size
start
)
-1
)
=
False
=
size
str
>=
size
start
&&
startsWith_
((
size
start
)
-1
)
where
startsWith_
-1
=
True
startsWith_
starti
=
case
start
.[
starti
]
==
str
.[
starti
]
of
True
=
startsWith_
(
starti
-1
)
=
False
=
start
.[
starti
]
==
str
.[
starti
]
&&
startsWith_
(
starti
-1
)
endsWith
::
!
String
!
String
->
Bool
endsWith
end
str
|
(
size
str
)
>=
(
size
end
)
=
endsWith_
((
size
end
)
-1
)
((
size
str
)
-1
)
=
False
=
size
str
>=
size
end
&&
endsWith_
(
size
end
-1
)
(
size
str
-1
)
where
endsWith_
-1
_
=
True
endsWith_
endi
stri
=
case
end
.[
endi
]
==
str
.[
stri
]
of
True
=
endsWith_
(
endi
-1
)
(
stri
-1
)
=
False
=
end
.[
endi
]
==
str
.[
stri
]
&&
endsWith_
(
endi
-1
)
(
stri
-1
)
charIndex
::
!
String
!
Int
!
Char
->
(!
Bool
,!
Int
)
charIndex
s
i
char
|
i
==
(
size
s
)
|
i
<
size
s
|
s
.[
i
]
==
char
=
(
True
,
i
)
=
charIndex
s
(
i
+1
)
char
|
i
==
size
s
=
(
False
,
size
s
)
|
i
<
(
size
s
)
|
s
.[
i
]
==
char
=
(
True
,
i
)
=
charIndex
s
(
i
+1
)
char
=
abort
"CharIndex: index out of range"
=
abort
"CharIndex: index out of range"
charIndexBackwards
::
!
String
!
Int
!
Char
->
(!
Bool
,!
Int
)
charIndexBackwards
s
i
char
|
i
==
(
-1
)
|
i
==
-1
=
(
False
,
size
s
)
|
s
.[
i
]
==
char
...
...
@@ -56,19 +48,22 @@ charIndexBackwards s i char
matchAt
::
!
String
!
String
!
Int
->
Bool
matchAt
s1
s2
p
|
((
size
s1
)
+
p
)
>
(
size
s2
)
=
False
=
eqS
((
size
s1
)
-
1
)
where
eqS
0
=
s1
.[
0
]
==
s2
.[
p
+
0
]
eqS
i
=
s1
.[
i
]
==
s2
.[
p
+
i
]
&&
eqS
(
i
-
1
)
=
size
s1
+
p
<=
size
s2
&&
match_at
0
p
where
match_at
::
!
Int
!
Int
->
Bool
match_at
i1
i2
|
i1
<
size
s1
=
s1
.[
i1
]==
s2
.[
i2
]
&&
match_at
(
i1
+1
)
(
i2
+1
)
=
True
countCharBackwards
::
!
Char
!
String
->
Int
countCharBackwards
chr
str
=
count
((
size
str
)
-1
)
=
count
((
size
str
)
-1
)
0
str
where
count
-1
=
0
count
pos
|
str
.[
pos
]
==
chr
=
1
+
count
(
pos
-1
)
=
0
count
::
!
Int
!
Int
!
String
->
Int
count
-1
n_chars
str
=
n_chars
count
pos
n_chars
str
|
str
.[
pos
]
==
chr
=
count
(
pos
-1
)
(
n_chars
+1
)
str
=
n_chars
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