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
179 ("manifestPython", builtin_manifest_python::INST),179 ("manifestPython", builtin_manifest_python::INST),
180 ("manifestPythonVars", builtin_manifest_python_vars::INST),180 ("manifestPythonVars", builtin_manifest_python_vars::INST),
181 ("manifestXmlJsonml", builtin_manifest_xml_jsonml::INST),181 ("manifestXmlJsonml", builtin_manifest_xml_jsonml::INST),
182 ("manifestIni", builtin_manifest_ini::INST),
182 // Parse183 // Parse
183 ("parseJson", builtin_parse_json::INST),184 ("parseJson", builtin_parse_json::INST),
184 ("parseYaml", builtin_parse_yaml::INST),185 ("parseYaml", builtin_parse_yaml::INST),
modifiedcrates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth
1mod ini;
1mod python;2mod python;
2mod toml;3mod toml;
3mod xml;4mod xml;
4mod yaml;5mod yaml;
56
7pub use ini::IniFormat;
6use jrsonnet_evaluator::{8use jrsonnet_evaluator::{
7 function::builtin,9 function::builtin,
8 manifest::{escape_string_json, JsonFormat, YamlStreamFormat},10 manifest::{escape_string_json, JsonFormat, YamlStreamFormat},
191 value.manifest(XmlJsonmlFormat::std_to_xml())193 value.manifest(XmlJsonmlFormat::std_to_xml())
192}194}
195
196#[builtin]
197pub fn builtin_manifest_ini(
198 ini: Val,
199
200 #[default(false)]
201 #[cfg(feature = "exp-preserve-order")]
202 preserve_order: bool,
203) -> Result<String> {
204 ini.manifest(IniFormat::std(
205 #[cfg(feature = "exp-preserve-order")]
206 preserve_order,
207 ))
208}
193209
modifiedcrates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth
196 #[cfg(feature = "exp-preserve-order")]196 #[cfg(feature = "exp-preserve-order")]
197 options.preserve_order,197 options.preserve_order,
198 ) {198 ) {
199 let value = value?;199 let value = value.with_description(|| format!("field <{key}> evaluation"))?;
200 if is_section(&value)? {200 if is_section(&value)? {
201 sections.push((key, value));201 sections.push((key, value));
202 } else {202 } else {
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
25 else25 else
26 error 'Assertion failed. ' + a + ' != ' + b,26 error 'Assertion failed. ' + a + ' != ' + b,
2727
28 manifestIni(ini)::
29 local body_lines(body) =
30 std.join([], [
31 local value_or_values = body[k];
32 if std.isArray(value_or_values) then
33 ['%s = %s' % [k, value] for value in value_or_values]
34 else
35 ['%s = %s' % [k, value_or_values]]
36
37 for k in std.objectFields(body)
38 ]);
39
40 local section_lines(sname, sbody) = ['[%s]' % [sname]] + body_lines(sbody),
41 main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],
42 all_sections = [
43 section_lines(k, ini.sections[k])
44 for k in std.objectFields(ini.sections)
45 ];
46 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),
47
48 mergePatch(target, patch)::28 mergePatch(target, patch)::
49 if std.isObject(patch) then29 if std.isObject(patch) then
50 local target_object =30 local target_object =