git.delta.rocks / jrsonnet / refs/commits / 88907d8b259a

difftreelog

perf move ini manifestification to native

Yaroslav Bolyukin2024-05-19parent: #0ef9787.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
4use jrsonnet_evaluator::manifest::{4use jrsonnet_evaluator::manifest::{
5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
6};6};
7use jrsonnet_stdlib::{TomlFormat, XmlJsonmlFormat, YamlFormat};7use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};
88
9#[derive(Clone, Copy, ValueEnum)]9#[derive(Clone, Copy, ValueEnum)]
10pub enum ManifestFormatName {10pub enum ManifestFormatName {
14 Yaml,14 Yaml,
15 Toml,15 Toml,
16 XmlJsonml,16 XmlJsonml,
17 Ini,
17}18}
1819
19#[derive(Parser)]20#[derive(Parser)]
72 preserve_order,73 preserve_order,
73 )),74 )),
74 ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),75 ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),
76 ManifestFormatName::Ini => Box::new(IniFormat::cli(
77 #[cfg(feature = "exp-preserve-order")]
78 preserve_order,
79 )),
75 }80 }
76 };81 };
77 if self.yaml_stream {82 if self.yaml_stream {
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -179,6 +179,7 @@
 		("manifestPython", builtin_manifest_python::INST),
 		("manifestPythonVars", builtin_manifest_python_vars::INST),
 		("manifestXmlJsonml", builtin_manifest_xml_jsonml::INST),
+		("manifestIni", builtin_manifest_ini::INST),
 		// Parse
 		("parseJson", builtin_parse_json::INST),
 		("parseYaml", builtin_parse_yaml::INST),
modifiedcrates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/mod.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/mod.rs
@@ -1,8 +1,10 @@
+mod ini;
 mod python;
 mod toml;
 mod xml;
 mod yaml;
 
+pub use ini::IniFormat;
 use jrsonnet_evaluator::{
 	function::builtin,
 	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},
@@ -190,3 +192,17 @@
 pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {
 	value.manifest(XmlJsonmlFormat::std_to_xml())
 }
+
+#[builtin]
+pub fn builtin_manifest_ini(
+	ini: Val,
+
+	#[default(false)]
+	#[cfg(feature = "exp-preserve-order")]
+	preserve_order: bool,
+) -> Result<String> {
+	ini.manifest(IniFormat::std(
+		#[cfg(feature = "exp-preserve-order")]
+		preserve_order,
+	))
+}
modifiedcrates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -196,7 +196,7 @@
 		#[cfg(feature = "exp-preserve-order")]
 		options.preserve_order,
 	) {
-		let value = value?;
+		let value = value.with_description(|| format!("field <{key}> evaluation"))?;
 		if is_section(&value)? {
 			sections.push((key, value));
 		} else {
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -25,26 +25,6 @@
     else
       error 'Assertion failed. ' + a + ' != ' + b,
 
-  manifestIni(ini)::
-    local body_lines(body) =
-      std.join([], [
-        local value_or_values = body[k];
-        if std.isArray(value_or_values) then
-          ['%s = %s' % [k, value] for value in value_or_values]
-        else
-          ['%s = %s' % [k, value_or_values]]
-
-        for k in std.objectFields(body)
-      ]);
-
-    local section_lines(sname, sbody) = ['[%s]' % [sname]] + body_lines(sbody),
-          main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],
-          all_sections = [
-      section_lines(k, ini.sections[k])
-      for k in std.objectFields(ini.sections)
-    ];
-    std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),
-
   mergePatch(target, patch)::
     if std.isObject(patch) then
       local target_object =