Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

do not allocate string to immediately push it

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jul 14, 2026, 12:57 PM +0100) commit 9a9a1636 parent aa58ba10 change-id yulusmwq
+80 -40
+80 -40
erlang-abstract-format/src/lib.rs
··· 1772 1772 } 1773 1773 1774 1774 self.new_top_level_form(); 1775 - self.code.push_str(&format!( 1776 - "-export([{}]).\n", 1777 - exported 1778 - .map(|(name, arity)| { format!("{}/{}", quote_atom_name(name.as_ref()), arity) }) 1779 - .join(", ") 1780 - )); 1775 + 1776 + self.code.push_str("-export(["); 1777 + let mut first = true; 1778 + for (name, arity) in exported { 1779 + if first { 1780 + first = false; 1781 + } else { 1782 + self.code.push_str(", "); 1783 + } 1784 + 1785 + self.code.push_str(&quote_atom_name(name.as_ref())); 1786 + self.code.push('/'); 1787 + self.code.push_str(&arity.to_string()) 1788 + } 1789 + self.code.push_str("]).\n"); 1781 1790 } 1782 1791 1783 1792 fn export_type_attribute<'a, Name: AsRef<str>>( ··· 1791 1800 } 1792 1801 1793 1802 self.new_top_level_form(); 1794 - self.code.push_str(&format!( 1795 - "-export_type([{}]).\n", 1796 - exported 1797 - .map(|(name, arity)| { format!("{}/{}", quote_atom_name(name.as_ref()), arity) }) 1798 - .join(", ") 1799 - )); 1803 + 1804 + self.code.push_str("-export_type(["); 1805 + let mut first = true; 1806 + for (name, arity) in exported { 1807 + if first { 1808 + first = false; 1809 + } else { 1810 + self.code.push_str(", "); 1811 + } 1812 + 1813 + self.code.push_str(&quote_atom_name(name.as_ref())); 1814 + self.code.push('/'); 1815 + self.code.push_str(&arity.to_string()) 1816 + } 1817 + self.code.push_str("]).\n"); 1800 1818 } 1801 1819 1802 1820 fn start_doc_attribute(&mut self) -> DocAttribute { ··· 1824 1842 1825 1843 fn compile_attribute<'a>(&mut self, arguments: impl IntoIterator<Item = &'a str>) { 1826 1844 self.new_top_level_form(); 1827 - self.code.push_str(&format!( 1828 - "-compile([{}]).\n", 1829 - arguments.into_iter().join(", ") 1830 - )) 1845 + 1846 + self.code.push_str("-compile(["); 1847 + 1848 + let mut first = true; 1849 + for argument in arguments { 1850 + if first { 1851 + first = false; 1852 + } else { 1853 + self.code.push_str(", "); 1854 + } 1855 + 1856 + self.code.push_str(argument); 1857 + } 1858 + self.code.push_str("]).\n"); 1831 1859 } 1832 1860 1833 1861 fn file_attribute(&mut self, file: &str, line: u32) { 1834 1862 self.new_top_level_form(); 1835 - self.code 1836 - .push_str(&format!("\n-file(\"{}\", {}).", file, line)); 1863 + self.code.push_str("\n-file(\""); 1864 + self.code.push_str(file); 1865 + self.code.push_str("\", "); 1866 + self.code.push_str(&line.to_string()); 1867 + self.code.push_str(")."); 1837 1868 } 1838 1869 1839 1870 fn start_record_attribute(&mut self, record_name: &str) -> RecordAttribute { 1840 1871 self.new_top_level_form(); 1841 - self.code 1842 - .push_str(&format!("-record({}, {{", quote_atom_name(record_name))); 1872 + self.code.push_str("-record("); 1873 + self.code.push_str(&quote_atom_name(record_name)); 1874 + self.code.push_str(", {"); 1843 1875 self.indentation += INDENT; 1844 1876 self.position 1845 1877 .push(PrettyEafPosition::RecordAttribute { first: true }); ··· 1863 1895 1864 1896 fn start_function_spec(&mut self, name: &str, _arity: usize) -> FunctionSpec { 1865 1897 self.new_top_level_form(); 1866 - self.code 1867 - .push_str(&format!("\n-spec {}", quote_atom_name(name))); 1898 + self.code.push_str("\n-spec "); 1899 + self.code.push_str(&quote_atom_name(name)); 1868 1900 self.position.push(PrettyEafPosition::FunctionSpec); 1869 1901 FunctionSpec { 1870 1902 representations: PrettyEaf::dummy_list(), ··· 2111 2143 }; 2112 2144 2113 2145 self.new_expression(); 2114 - self.code.push_str(&format!( 2115 - "{}:{}", 2116 - quote_atom_name(&module.0), 2117 - quote_atom_name(function), 2118 - )); 2146 + self.code.push_str(&quote_atom_name(&module.0)); 2147 + self.code.push(':'); 2148 + self.code.push_str(&quote_atom_name(function)); 2119 2149 self.position.push(PrettyEafPosition::FunctionCall { 2120 2150 expected: ExpectedCallItem::Arguments { first: true }, 2121 2151 called_item_needs_wrapping: false, ··· 2398 2428 } 2399 2429 self.code.push_str(&quote_atom_name(name)); 2400 2430 self.code.push('/'); 2401 - self.code.push_str(&format!("{arity}")); 2431 + self.code.push_str(&arity.to_string()); 2402 2432 } 2403 2433 2404 2434 fn match_operator(&mut self) { ··· 2430 2460 fn int_pattern(&mut self, number: BigInt) { 2431 2461 self.do_not_wrap_if_segment_value_or_size(); 2432 2462 self.new_pattern(); 2433 - self.code.push_str(&format!("{number}")); 2463 + self.code.push_str(&number.to_string()); 2434 2464 } 2435 2465 2436 2466 fn float_pattern(&mut self, number: f64) { ··· 2501 2531 fn int(&mut self, number: BigInt) { 2502 2532 self.do_not_wrap_if_segment_value_or_size(); 2503 2533 self.new_expression(); 2504 - self.code.push_str(&format!("{number}")); 2534 + self.code.push_str(&number.to_string()); 2505 2535 } 2506 2536 2507 2537 fn float(&mut self, number: f64) { ··· 2675 2705 if !*first { 2676 2706 self.code.push(','); 2677 2707 } 2678 - self.code.push('\n'); 2679 - self.code.push_str(&" ".repeat(self.indentation)); 2680 2708 *first = false; 2709 + self.code.push('\n'); 2710 + self.push_indentation(); 2681 2711 } 2682 2712 2683 2713 PrettyEafPosition::BitArraySegment { ··· 3039 3069 PrettyEafPosition::AnonymousFunctionStatement { .. } => { 3040 3070 self.indentation -= INDENT; 3041 3071 self.code.push('\n'); 3042 - self.code.push_str(&" ".repeat(self.indentation)); 3072 + self.push_indentation(); 3043 3073 self.code.push_str("end") 3044 3074 } 3045 3075 // When we're done generating statements for a block we need to add ··· 3047 3077 PrettyEafPosition::Block { .. } => { 3048 3078 self.indentation -= INDENT; 3049 3079 self.code.push('\n'); 3050 - self.code.push_str(&" ".repeat(self.indentation)); 3080 + self.push_indentation(); 3051 3081 self.code.push_str("end"); 3052 3082 } 3053 3083 // When we're done generating code for a function spec we want to ··· 3135 3165 } => { 3136 3166 self.indentation -= INDENT; 3137 3167 self.code.push('\n'); 3138 - self.code.push_str(&" ".repeat(self.indentation)); 3168 + self.push_indentation(); 3139 3169 self.code.push_str("end"); 3140 3170 } 3141 3171 ··· 3153 3183 PrettyEafPosition::Map { .. } => { 3154 3184 self.indentation -= INDENT; 3155 3185 self.code.push('\n'); 3156 - self.code.push_str(&" ".repeat(self.indentation)); 3186 + self.push_indentation(); 3157 3187 self.code.push('}'); 3158 3188 } 3159 3189 PrettyEafPosition::RecordAttribute { .. } => { 3160 3190 self.indentation -= INDENT; 3161 3191 self.code.push('\n'); 3162 - self.code.push_str(&" ".repeat(self.indentation)); 3192 + self.push_indentation(); 3163 3193 self.code.push_str("})."); 3164 3194 } 3165 3195 ··· 3386 3416 segment_size_needs_wrapping: _, 3387 3417 }) = self.position.last() 3388 3418 { 3389 - self.code.push_str(&format!("\"{content}\"")) 3419 + self.code.push('"'); 3420 + self.code.push_str(&content); 3421 + self.code.push('"'); 3390 3422 } else { 3391 - self.code.push_str(&format!("~\"{content}\"",)); 3423 + self.code.push_str("~\""); 3424 + self.code.push_str(&content); 3425 + self.code.push('"'); 3392 3426 } 3393 3427 } 3394 3428 ··· 3582 3616 self.code.push(','); 3583 3617 } 3584 3618 self.code.push('\n'); 3585 - self.code.push_str(&" ".repeat(self.indentation)); 3619 + self.push_indentation(); 3620 + } 3621 + 3622 + fn push_indentation(&mut self) { 3623 + for _ in 0..self.indentation { 3624 + self.code.push(' '); 3625 + } 3586 3626 } 3587 3627 3588 3628 /// This produces a pretty printed error message including the current