difftreelog
perf move ini manifestification to native
in: master
5 files changed
crates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth4use 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};889#[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}181919#[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 {crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth179 ("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 // Parse183 ("parseJson", builtin_parse_json::INST),184 ("parseJson", builtin_parse_json::INST),184 ("parseYaml", builtin_parse_yaml::INST),185 ("parseYaml", builtin_parse_yaml::INST),crates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth1mod ini;1mod python;2mod python;2mod toml;3mod toml;3mod xml;4mod xml;4mod yaml;5mod yaml;567pub 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}195196#[builtin]197pub fn builtin_manifest_ini(198 ini: Val,199200 #[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}193209crates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth196 #[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 {crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth25 else25 else26 error 'Assertion failed. ' + a + ' != ' + b,26 error 'Assertion failed. ' + a + ' != ' + b,272728 manifestIni(ini)::29 local body_lines(body) =30 std.join([], [31 local value_or_values = body[k];32 if std.isArray(value_or_values) then33 ['%s = %s' % [k, value] for value in value_or_values]34 else35 ['%s = %s' % [k, value_or_values]]3637 for k in std.objectFields(body)38 ]);3940 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) + ['']),4748 mergePatch(target, patch)::28 mergePatch(target, patch)::49 if std.isObject(patch) then29 if std.isObject(patch) then50 local target_object =30 local target_object =