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}
after · crates/jrsonnet-stdlib/src/manifest/mod.rs
1mod ini;2mod python;3mod toml;4mod xml;5mod yaml;67pub use ini::IniFormat;8use jrsonnet_evaluator::{9	function::builtin,10	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},11	IStr, ObjValue, Result, Val,12};13pub use python::{PythonFormat, PythonVarsFormat};14pub use toml::TomlFormat;15pub use xml::XmlJsonmlFormat;16pub use yaml::YamlFormat;1718#[builtin]19pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {20	Ok(escape_string_json(&str_))21}2223#[builtin]24pub fn builtin_escape_string_python(str: IStr) -> Result<String> {25	Ok(escape_string_json(&str))26}2728#[builtin]29pub fn builtin_manifest_json_ex(30	value: Val,31	indent: String,32	newline: Option<IStr>,33	key_val_sep: Option<IStr>,3435	#[default(false)]36	#[cfg(feature = "exp-preserve-order")]37	preserve_order: bool,38) -> Result<String> {39	let newline = newline.as_deref().unwrap_or("\n");40	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");41	value.manifest(JsonFormat::std_to_json(42		indent,43		newline,44		key_val_sep,45		#[cfg(feature = "exp-preserve-order")]46		preserve_order,47	))48}4950#[builtin]51pub fn builtin_manifest_json(52	value: Val,5354	#[default(false)]55	#[cfg(feature = "exp-preserve-order")]56	preserve_order: bool,57) -> Result<String> {58	builtin_manifest_json_ex(59		value,60		"    ".to_owned(),61		None,62		None,63		#[cfg(feature = "exp-preserve-order")]64		preserve_order,65	)66}6768#[builtin]69pub fn builtin_manifest_json_minified(70	value: Val,7172	#[default(false)]73	#[cfg(feature = "exp-preserve-order")]74	preserve_order: bool,75) -> Result<String> {76	value.manifest(JsonFormat::minify(77		#[cfg(feature = "exp-preserve-order")]78		preserve_order,79	))80}8182#[builtin]83pub fn builtin_manifest_yaml_doc(84	value: Val,85	#[default(false)] indent_array_in_object: bool,86	#[default(true)] quote_keys: bool,8788	#[default(false)]89	#[cfg(feature = "exp-preserve-order")]90	preserve_order: bool,91) -> Result<String> {92	value.manifest(YamlFormat::std_to_yaml(93		indent_array_in_object,94		quote_keys,95		#[cfg(feature = "exp-preserve-order")]96		preserve_order,97	))98}99100#[builtin]101pub fn builtin_manifest_yaml_stream(102	value: Val,103	#[default(false)] indent_array_in_object: bool,104	#[default(true)] c_document_end: bool,105	#[default(true)] quote_keys: bool,106107	#[default(false)]108	#[cfg(feature = "exp-preserve-order")]109	preserve_order: bool,110) -> Result<String> {111	value.manifest(YamlStreamFormat::std_yaml_stream(112		YamlFormat::std_to_yaml(113			indent_array_in_object,114			quote_keys,115			#[cfg(feature = "exp-preserve-order")]116			preserve_order,117		),118		c_document_end,119	))120}121122#[builtin]123pub fn builtin_manifest_toml_ex(124	value: ObjValue,125	indent: String,126127	#[default(false)]128	#[cfg(feature = "exp-preserve-order")]129	preserve_order: bool,130) -> Result<String> {131	Val::Obj(value).manifest(TomlFormat::std_to_toml(132		indent,133		#[cfg(feature = "exp-preserve-order")]134		preserve_order,135	))136}137138#[builtin]139pub fn builtin_manifest_toml(140	value: ObjValue,141142	#[default(false)]143	#[cfg(feature = "exp-preserve-order")]144	preserve_order: bool,145) -> Result<String> {146	builtin_manifest_toml_ex(147		value,148		"  ".to_owned(),149		#[cfg(feature = "exp-preserve-order")]150		preserve_order,151	)152}153154#[builtin]155pub fn builtin_to_string(a: Val) -> Result<IStr> {156	a.to_string()157}158159#[builtin]160pub fn builtin_manifest_python(161	v: Val,162163	#[default(false)]164	#[cfg(feature = "exp-preserve-order")]165	preserve_order: bool,166) -> Result<String> {167	v.manifest(PythonFormat::std(168		#[cfg(feature = "exp-preserve-order")]169		preserve_order,170	))171}172#[builtin]173pub fn builtin_manifest_python_vars(174	conf: Val,175176	#[default(false)]177	#[cfg(feature = "exp-preserve-order")]178	preserve_order: bool,179) -> Result<String> {180	conf.manifest(PythonVarsFormat::std(181		#[cfg(feature = "exp-preserve-order")]182		preserve_order,183	))184}185186#[builtin]187pub fn builtin_escape_string_xml(str_: String) -> String {188	xml::escape_string_xml(str_.as_str())189}190191#[builtin]192pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {193	value.manifest(XmlJsonmlFormat::std_to_xml())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}
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 =