alpha
Login
or
Join now
nandi.uk
/
gleam
Star
2
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Fork of daniellemaywood.uk/gleam — Wasm codegen work
Star
2
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
try optimisation adding join variants
author
Giacomo Cavalieri
committer
Louis Pilfold
date
1 month ago
(Jun 15, 2026, 12:37 PM +0100)
commit
34f2c50e
34f2c50e976320da39b97ceeb5131038dc0a2a3b
parent
cc44d4c8
cc44d4c8b0b93a72be51b25f345090e5da59428d
change-id
vstxktvt
vstxktvtsxnzsnxkkrvuqlxrpupzpmvy
+60
-9
1 changed file
Expand all
Collapse all
Unified
Split
compiler-core
src
pretty_arena.rs
+60
-9
compiler-core/src/pretty_arena.rs
View file
Reviewed
···
214
214
| PrintableDocument::NextBreakFits(..)
215
215
| PrintableDocument::Break { .. }
216
216
| PrintableDocument::Join(..)
217
217
+
| PrintableDocument::Join3(..)
218
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
294
-
second: impl Documentable<'string, 'doc>,
296
296
+
new: impl Documentable<'string, 'doc>,
295
297
) -> Document<'string, 'doc> {
298
298
+
let new = new.to_doc(arena);
299
299
+
if let PrintableDocument::Empty = new.0 {
300
300
+
return self;
301
301
+
}
302
302
+
296
303
match self.0 {
297
297
-
PrintableDocument::Empty => second.to_doc(arena),
304
304
+
PrintableDocument::Empty => new,
305
305
+
PrintableDocument::Join(first, second) => Document(
306
306
+
arena
307
307
+
.documents
308
308
+
.alloc(PrintableDocument::Join3(*first, *second, new)),
309
309
+
),
310
310
+
PrintableDocument::Join3(first, second, third) => Document(
311
311
+
arena
312
312
+
.documents
313
313
+
.alloc(PrintableDocument::Join4(*first, *second, *third, new)),
314
314
+
),
298
315
PrintableDocument::Line(..)
299
299
-
| PrintableDocument::Join(..)
316
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
309
-
let second = second.to_doc(arena);
310
310
-
if let PrintableDocument::Empty = second.0 {
311
311
-
self
312
312
-
} else {
313
313
-
Document(arena.documents.alloc(PrintableDocument::Join(self, second)))
314
314
-
}
326
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
359
+
PrintableDocument::Join3(first, second, third) => {
360
360
+
first.is_empty() && second.is_empty() && third.is_empty()
361
361
+
}
362
362
+
PrintableDocument::Join4(first, second, third, fourth) => {
363
363
+
first.is_empty() && second.is_empty() && third.is_empty() && fourth.is_empty()
364
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
426
+
Join3(
427
427
+
Document<'string, 'doc>,
428
428
+
Document<'string, 'doc>,
429
429
+
Document<'string, 'doc>,
430
430
+
),
431
431
+
Join4(
432
432
+
Document<'string, 'doc>,
433
433
+
Document<'string, 'doc>,
434
434
+
Document<'string, 'doc>,
435
435
+
Document<'string, 'doc>,
436
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
858
+
PrintableDocument::Join3(first, second, third) => {
859
859
+
docs.push_front((indent, mode, *third));
860
860
+
docs.push_front((indent, mode, *second));
861
861
+
docs.push_front((indent, mode, *first));
862
862
+
}
863
863
+
PrintableDocument::Join4(first, second, third, fourth) => {
864
864
+
docs.push_front((indent, mode, *fourth));
865
865
+
docs.push_front((indent, mode, *third));
866
866
+
docs.push_front((indent, mode, *second));
867
867
+
docs.push_front((indent, mode, *first));
868
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
1071
+
docs.push_front((indent, mode, *second));
1072
1072
+
docs.push_front((indent, mode, *first));
1073
1073
+
}
1074
1074
+
PrintableDocument::Join3(first, second, third) => {
1075
1075
+
docs.push_front((indent, mode, *third));
1076
1076
+
docs.push_front((indent, mode, *second));
1077
1077
+
docs.push_front((indent, mode, *first));
1078
1078
+
}
1079
1079
+
PrintableDocument::Join4(first, second, third, fourth) => {
1080
1080
+
docs.push_front((indent, mode, *fourth));
1081
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
}