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

Configure Feed

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

try optimisation adding join variants

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jun 15, 2026, 12:37 PM +0100) commit 34f2c50e parent cc44d4c8 change-id vstxktvt
+60 -9
+60 -9
compiler-core/src/pretty_arena.rs
··· 214 214 | PrintableDocument::NextBreakFits(..) 215 215 | PrintableDocument::Break { .. } 216 216 | PrintableDocument::Join(..) 217 + | PrintableDocument::Join3(..) 218 + | PrintableDocument::Join4(..) 217 219 | PrintableDocument::Nest(..) => Document(arena.documents.alloc(PrintableDocument::Group(self))), 218 220 } 219 221 } ··· 291 293 pub fn append( 292 294 self, 293 295 arena: &'doc DocumentArena<'string, 'doc>, 294 - second: impl Documentable<'string, 'doc>, 296 + new: impl Documentable<'string, 'doc>, 295 297 ) -> Document<'string, 'doc> { 298 + let new = new.to_doc(arena); 299 + if let PrintableDocument::Empty = new.0 { 300 + return self; 301 + } 302 + 296 303 match self.0 { 297 - PrintableDocument::Empty => second.to_doc(arena), 304 + PrintableDocument::Empty => new, 305 + PrintableDocument::Join(first, second) => Document( 306 + arena 307 + .documents 308 + .alloc(PrintableDocument::Join3(*first, *second, new)), 309 + ), 310 + PrintableDocument::Join3(first, second, third) => Document( 311 + arena 312 + .documents 313 + .alloc(PrintableDocument::Join4(*first, *second, *third, new)), 314 + ), 298 315 PrintableDocument::Line(..) 299 - | PrintableDocument::Join(..) 316 + | PrintableDocument::Join4(..) 300 317 | PrintableDocument::ForceBroken(..) 301 318 | PrintableDocument::NextBreakFits(..) 302 319 | PrintableDocument::Break { .. } ··· 306 323 | PrintableDocument::EcoString { .. } 307 324 | PrintableDocument::ZeroWidthString { .. } 308 325 | PrintableDocument::CursorPositionObserver { .. } => { 309 - let second = second.to_doc(arena); 310 - if let PrintableDocument::Empty = second.0 { 311 - self 312 - } else { 313 - Document(arena.documents.alloc(PrintableDocument::Join(self, second))) 314 - } 326 + Document(arena.documents.alloc(PrintableDocument::Join(self, new))) 315 327 } 316 328 } 317 329 } ··· 344 356 | PrintableDocument::Group(document) 345 357 | PrintableDocument::NextBreakFits(document, _) => document.is_empty(), 346 358 PrintableDocument::Join(first, second) => first.is_empty() && second.is_empty(), 359 + PrintableDocument::Join3(first, second, third) => { 360 + first.is_empty() && second.is_empty() && third.is_empty() 361 + } 362 + PrintableDocument::Join4(first, second, third, fourth) => { 363 + first.is_empty() && second.is_empty() && third.is_empty() && fourth.is_empty() 364 + } 347 365 // Zero-width strings don't count towards line length, but they are 348 366 // still printed and so are not empty. (Unless their string contents 349 367 // is also empty) ··· 405 423 /// `Document::Line` is used. 406 424 // maybe experiment with Slice(&'doc [Document<'string, 'doc>]), 407 425 Join(Document<'string, 'doc>, Document<'string, 'doc>), 426 + Join3( 427 + Document<'string, 'doc>, 428 + Document<'string, 'doc>, 429 + Document<'string, 'doc>, 430 + ), 431 + Join4( 432 + Document<'string, 'doc>, 433 + Document<'string, 'doc>, 434 + Document<'string, 'doc>, 435 + Document<'string, 'doc>, 436 + ), 408 437 409 438 /// Nests the given document by the given indent, depending on the specified 410 439 /// condition. See `Document::nest`, `Document::set_nesting` and ··· 826 855 docs.push_front((indent, mode, *second)); 827 856 docs.push_front((indent, mode, *first)); 828 857 } 858 + PrintableDocument::Join3(first, second, third) => { 859 + docs.push_front((indent, mode, *third)); 860 + docs.push_front((indent, mode, *second)); 861 + docs.push_front((indent, mode, *first)); 862 + } 863 + PrintableDocument::Join4(first, second, third, fourth) => { 864 + docs.push_front((indent, mode, *fourth)); 865 + docs.push_front((indent, mode, *third)); 866 + docs.push_front((indent, mode, *second)); 867 + docs.push_front((indent, mode, *first)); 868 + } 829 869 830 870 // A `Nest` document doesn't result in anything being printed, its 831 871 // only effect is to increase the current nesting level for the ··· 1028 1068 // The array needs to be reversed to preserve the order of the 1029 1069 // documents since each one is pushed _to the front_ of the 1030 1070 // queue of documents to check. 1071 + docs.push_front((indent, mode, *second)); 1072 + docs.push_front((indent, mode, *first)); 1073 + } 1074 + PrintableDocument::Join3(first, second, third) => { 1075 + docs.push_front((indent, mode, *third)); 1076 + docs.push_front((indent, mode, *second)); 1077 + docs.push_front((indent, mode, *first)); 1078 + } 1079 + PrintableDocument::Join4(first, second, third, fourth) => { 1080 + docs.push_front((indent, mode, *fourth)); 1081 + docs.push_front((indent, mode, *third)); 1031 1082 docs.push_front((indent, mode, *second)); 1032 1083 docs.push_front((indent, mode, *first)); 1033 1084 }