mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Optimize escapeLabelValue for the common case
Avoid an expensive string copy for the common case of there being no characters to escape in the label value.
This commit is contained in:
1 parent
cdb048741c
commit
a08087c5e8
1 file changed
+4
@@ -206,6 +206,7 @@ class Collector {
|
||||
async* collect() { }
|
||||
}
|
||||
|
||||
const labelEscapesChars = /[\\\n\"]/;
|
||||
/**
|
||||
* Escapes a label value in accordance with the text exposition format
|
||||
*
|
||||
@@ -214,6 +215,9 @@ class Collector {
|
||||
* @private
|
||||
*/
|
||||
function escapeLabelValue(value) {
|
||||
if (!labelEscapesChars.test(value)) {
|
||||
return value;
|
||||
}
|
||||
return value
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/\n/g, "\\n")
|
||||
|
||||
Reference in new issue
Block a user