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
--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -4,7 +4,7 @@
 use jrsonnet_evaluator::manifest::{
 	JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
 };
-use jrsonnet_stdlib::{TomlFormat, XmlJsonmlFormat, YamlFormat};
+use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};
 
 #[derive(Clone, Copy, ValueEnum)]
 pub enum ManifestFormatName {
@@ -14,6 +14,7 @@
 	Yaml,
 	Toml,
 	XmlJsonml,
+	Ini,
 }
 
 #[derive(Parser)]
@@ -72,6 +73,10 @@
 					preserve_order,
 				)),
 				ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),
+				ManifestFormatName::Ini => Box::new(IniFormat::cli(
+					#[cfg(feature = "exp-preserve-order")]
+					preserve_order,
+				)),
 			}
 		};
 		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
before · crates/jrsonnet-stdlib/src/manifest/mod.rs
1mod python;2mod toml;3mod xml;4mod yaml;56use jrsonnet_evaluator::{7	function::builtin,8	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},9	IStr, ObjValue, Result, Val,10};11pub use python::{PythonFormat, PythonVarsFormat};12pub use toml::TomlFormat;13pub use xml::XmlJsonmlFormat;14pub use yaml::YamlFormat;1516#[builtin]17pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {18	Ok(escape_string_json(&str_))19}2021#[builtin]22pub fn builtin_escape_string_python(str: IStr) -> Result<String> {23	Ok(escape_string_json(&str))24}2526#[builtin]27pub fn builtin_manifest_json_ex(28	value: Val,29	indent: String,30	newline: Option<IStr>,31	key_val_sep: Option<IStr>,3233	#[default(false)]34	#[cfg(feature = "exp-preserve-order")]35	preserve_order: bool,36) -> Result<String> {37	let newline = newline.as_deref().unwrap_or("\n");38	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");39	value.manifest(JsonFormat::std_to_json(40		indent,41		newline,42		key_val_sep,43		#[cfg(feature = "exp-preserve-order")]44		preserve_order,45	))46}4748#[builtin]49pub fn builtin_manifest_json(50	value: Val,5152	#[default(false)]53	#[cfg(feature = "exp-preserve-order")]54	preserve_order: bool,55) -> Result<String> {56	builtin_manifest_json_ex(57		value,58		"    ".to_owned(),59		None,60		None,61		#[cfg(feature = "exp-preserve-order")]62		preserve_order,63	)64}6566#[builtin]67pub fn builtin_manifest_json_minified(68	value: Val,6970	#[default(false)]71	#[cfg(feature = "exp-preserve-order")]72	preserve_order: bool,73) -> Result<String> {74	value.manifest(JsonFormat::minify(75		#[cfg(feature = "exp-preserve-order")]76		preserve_order,77	))78}7980#[builtin]81pub fn builtin_manifest_yaml_doc(82	value: Val,83	#[default(false)] indent_array_in_object: bool,84	#[default(true)] quote_keys: bool,8586	#[default(false)]87	#[cfg(feature = "exp-preserve-order")]88	preserve_order: bool,89) -> Result<String> {90	value.manifest(YamlFormat::std_to_yaml(91		indent_array_in_object,92		quote_keys,93		#[cfg(feature = "exp-preserve-order")]94		preserve_order,95	))96}9798#[builtin]99pub fn builtin_manifest_yaml_stream(100	value: Val,101	#[default(false)] indent_array_in_object: bool,102	#[default(true)] c_document_end: bool,103	#[default(true)] quote_keys: bool,104105	#[default(false)]106	#[cfg(feature = "exp-preserve-order")]107	preserve_order: bool,108) -> Result<String> {109	value.manifest(YamlStreamFormat::std_yaml_stream(110		YamlFormat::std_to_yaml(111			indent_array_in_object,112			quote_keys,113			#[cfg(feature = "exp-preserve-order")]114			preserve_order,115		),116		c_document_end,117	))118}119120#[builtin]121pub fn builtin_manifest_toml_ex(122	value: ObjValue,123	indent: String,124125	#[default(false)]126	#[cfg(feature = "exp-preserve-order")]127	preserve_order: bool,128) -> Result<String> {129	Val::Obj(value).manifest(TomlFormat::std_to_toml(130		indent,131		#[cfg(feature = "exp-preserve-order")]132		preserve_order,133	))134}135136#[builtin]137pub fn builtin_manifest_toml(138	value: ObjValue,139140	#[default(false)]141	#[cfg(feature = "exp-preserve-order")]142	preserve_order: bool,143) -> Result<String> {144	builtin_manifest_toml_ex(145		value,146		"  ".to_owned(),147		#[cfg(feature = "exp-preserve-order")]148		preserve_order,149	)150}151152#[builtin]153pub fn builtin_to_string(a: Val) -> Result<IStr> {154	a.to_string()155}156157#[builtin]158pub fn builtin_manifest_python(159	v: Val,160161	#[default(false)]162	#[cfg(feature = "exp-preserve-order")]163	preserve_order: bool,164) -> Result<String> {165	v.manifest(PythonFormat::std(166		#[cfg(feature = "exp-preserve-order")]167		preserve_order,168	))169}170#[builtin]171pub fn builtin_manifest_python_vars(172	conf: Val,173174	#[default(false)]175	#[cfg(feature = "exp-preserve-order")]176	preserve_order: bool,177) -> Result<String> {178	conf.manifest(PythonVarsFormat::std(179		#[cfg(feature = "exp-preserve-order")]180		preserve_order,181	))182}183184#[builtin]185pub fn builtin_escape_string_xml(str_: String) -> String {186	xml::escape_string_xml(str_.as_str())187}188189#[builtin]190pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {191	value.manifest(XmlJsonmlFormat::std_to_xml())192}
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 =