Message270469
Serhiy suggested this in Rietveld:
> For additional optimization we can pack all constant strings, parsed formats and
> flags in one constant object and use the single LOAD_CONST. But this requires
> much larger changes (perhaps including changing the marshal format), and the
> benefit may be small. Maybe we'll get to it eventually, if this approach proves
> efficient enough.
I was thinking about this and got an idea on how to do this too, without changes to marshal. Essentially, let TOS be a tuple of
(flags, str1, str2, str3, str4, str5, str6, str7, str8, str9...)
flags would be n bytes for n-part format string; each byte would tell whether:
- the next component is a constant string (bit 0 = 0) from the tuple
- the next component is an interpolated value (bit 0 = 1)
- and whether it has !s, !r, !a or default conversions (bits 1-2)
- and whether it has extra argument to format() or not (bit 3) (argument is the next string from the tuple)
thus that tuple for
a, b = 'Hello', 'World!'
f'{a!s} {b:10}!'
would be
(b'\x03\x00\x05\x00', ' ', '10', '!')
and the opcodes would be
LOAD_FAST (b)
LOAD_FAST (a)
LOAD_CONST (0) (the tuple)
BUILD_FORMAT_STRING 3 |
|
Date |
User |
Action |
Args |
2016-07-15 07:03:01 | ztane | set | recipients:
+ ztane, rhettinger, mjpieters, eric.smith, serhiy.storchaka, Demur Rumed |
2016-07-15 07:03:00 | ztane | set | messageid: <1468566180.82.0.11409853182.issue27078@psf.upfronthosting.co.za> |
2016-07-15 07:03:00 | ztane | link | issue27078 messages |
2016-07-15 07:03:00 | ztane | create | |
|