You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`src/uk.co.terryburton.bwipp.upr`- Resource name to path mapping for all resources; required by Distiller; build system uses the order to determine resource order in monolithic and standalone outputs
105
-
-`tests/ps_tests/*.ps.test` - PostScript test files
104
+
-`src/*.ps.src`- PostScript resource source files
105
+
-`src/uk.co.terryburton.bwipp.upr` – PostScript resource index mapping resource names to file paths; required by Distiller and used by the build system to enforce resource order in monolithic and standalone outputs
106
+
-`tests/ps_tests/*.ps.test`- PostScript test files
- Prefer stack manipulation over creating intermediate dictionaries
434
445
446
+
**Conditional Assignment Pattern**
447
+
448
+
Use an inline condition when performing simple conditional assignments:
449
+
450
+
```postscript
451
+
% Bad: Verbose
452
+
condition {
453
+
/a 2 def
454
+
} {
455
+
/a 5 def
456
+
} ifelse
457
+
458
+
% Good: Concise
459
+
/a condition { 2 } { 5 } ifelse def
460
+
```
461
+
462
+
463
+
**"Switch" blocks (short circuit)**
464
+
465
+
Long `ifelse` chains should be avoided by using a "common exit" pattern,
466
+
clearly denoted by a comment on the first line:
467
+
468
+
```postscript
469
+
% Bad: Hard to modify
470
+
condition1 {
471
+
/c1
472
+
} {
473
+
condition2 {
474
+
/c2
475
+
} ... {
476
+
/default
477
+
} ifelse ... } ifelse
478
+
479
+
% Good: Clarity
480
+
1 { % Common exit
481
+
condition1 { /c1 exit } if
482
+
condition2 { /c2 exit } if
483
+
...
484
+
/default
485
+
} repeat
486
+
/result exch def
487
+
```
488
+
489
+
**Loops with conditional exit**
490
+
491
+
Loops should be commented as such in the first line:
492
+
493
+
{ % loop
494
+
condition { exit } if
495
+
...
496
+
} loop
497
+
498
+
435
499
### Anti-patterns
436
500
437
501
- Creating variables (dictionary entries) in hot loops
438
502
- Defining static data in the main procedure (hoist to define time, then use `//name`)
439
503
- Computing derived data on every invocation (use latevars)
440
504
441
-
### Hot Loop Stack Pattern
505
+
**Hot Loop Stack Pattern**
442
506
443
507
In high computational complexity loops, avoid `/idx exch def`. Keep loop index
444
508
on stack, reference with `index` and finally consume with `roll` (rather than
445
509
`pop`):
446
510
447
511
```postscript
448
512
% Bad: Creates dictionary entry each iteration
449
-
0 1 k { % E.g. k from outer loop
513
+
0 1 k { % E.g. k from an outer loop
450
514
/idx exch def
451
515
% Stuff using "idx" variable...
452
516
arr k idx sub 1 sub get
453
517
} for
454
518
455
-
% Good: Loop indexconsumed by roll
519
+
% Good: Iterator referenced by "index" and finally consumed by "roll"
456
520
0 1 k 1 sub { % idx on stack
457
521
% Stuff using "N index" to access idx on the stack...
458
522
% Finally, roll moves idx to top where we consume it:
@@ -463,6 +527,7 @@ on stack, reference with `index` and finally consume with `roll` (rather than
463
527
The RSEC loops in qrcode, datamatrix, pdf417 demonstrate advanced uses of this
464
528
pattern, including stack-based access to variables outside of the inner loop.
465
529
530
+
466
531
### Profiling
467
532
468
533
Simple profiling of the overall runtime for some encoder:
@@ -750,9 +815,9 @@ Some PLRM terminology is a source of confusion. As a result of the following com
750
815
/b a def
751
816
```
752
817
753
-
-a is referred to as the "object" (within the currentdict)
754
-
- The --array-- created by "]" is referred to as "the storage for the object in VM" (either global or local VM depending on globalstatus)
755
-
-b is also an "object" that refers to the same VM storage as a
818
+
-`a` is referred to as the "object" (within the currentdict)
819
+
- The `--array--` created by `]` is referred to as "the storage for the object in VM" (either global or local VM depending on the allocation mode indicated by `globalstatus`)
820
+
-`b` is also an "object" that refers to the same VM storage as `a`
756
821
757
822
The terminology differs from many languages where the array itself would be referred to as an object and a and b would be referred to as names or references.
0 commit comments