Skip to content

Commit c1b3aa8

Browse files
committed
perf(function): cache ValueFactory regexes
1 parent a46d418 commit c1b3aa8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
#### [Permission system](https://quarkdown.com/wiki/cli-compiler#permissions)
8+
9+
Quarkdown's permission system controls what a document can access during compilation, for increased safety.
10+
If the compiler attempts an action that requires a permission it doesn't have, an error is raised.
11+
12+
You can grant or revoke permissions with the `--allow` and `--deny` flags:
13+
14+
```shell
15+
quarkdown c main.qd --allow global-read --deny native-content
16+
```
17+
18+
Available permissions: `project-read` (default), `global-read`, `network`, `native-content` (default), `all`. See the wiki page for more details.
19+
520
### Changed
621

722
#### Parallel rendering

quarkdown-core/src/main/kotlin/com/quarkdown/core/function/value/factory/ValueFactory.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,24 @@ import com.quarkdown.core.pipeline.stages.ParsingStage
6262
import com.quarkdown.core.util.iterator
6363
import com.quarkdown.core.util.node.conversion.list.MarkdownListToCollectionValue
6464
import com.quarkdown.core.util.node.conversion.list.MarkdownListToDictionaryValue
65+
import kotlin.collections.map
6566

6667
/**
6768
* Prefix that forces a generic expression to be parsed as a lambda block.
6869
* @see ValueFactory.expression
6970
*/
7071
private const val EXPRESSION_FORCE_LAMBDA_PREFIX = "@lambda "
7172

73+
/**
74+
* Pre-compiled regex for stripping comments from expressions.
75+
*/
76+
private val COMMENT_REGEX = PatternHelpers.COMMENT.toRegex()
77+
78+
/**
79+
* Pre-compiled regex for splitting whitespace-separated size values.
80+
*/
81+
private val WHITESPACE_REGEX = "\\s+".toRegex()
82+
7283
/**
7384
* Factory of [Value] wrappers from raw data.
7485
* @see com.quarkdown.core.function.reflect.FromDynamicType
@@ -213,7 +224,7 @@ object ValueFactory {
213224
fun sizes(raw: Any): ObjectValue<Sizes> {
214225
if (raw is Sizes) return ObjectValue(raw)
215226

216-
val parts = raw.toString().split("\\s+".toRegex())
227+
val parts = raw.toString().split(WHITESPACE_REGEX)
217228
val iterator = parts.iterator()
218229

219230
return ObjectValue(
@@ -541,7 +552,7 @@ object ValueFactory {
541552
}
542553

543554
// Strip comments.
544-
val rawCode = raw.toString().replace(PatternHelpers.COMMENT.toRegex(), "")
555+
val rawCode = raw.toString().replace(COMMENT_REGEX, "")
545556

546557
if (rawCode.isEmpty()) return DynamicValue("")
547558

0 commit comments

Comments
 (0)