-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Formatting: handle XTPUSHSGR/XTPOPSGR sequences #10208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -795,8 +795,9 @@ public enum ShowWindowCommands : int | |
| } | ||
|
|
||
| Describe "Console host api tests" -Tag CI { | ||
| Context "String escape sequences" { | ||
| Context "String escape and control sequences" { | ||
| $esc = [char]0x1b | ||
| $csi = [char]0x9b | ||
| $testCases = | ||
| @{InputObject = "abc"; Length = 3; Name = "No escapes"}, | ||
| @{InputObject = "${esc} [31mabc"; Length = 9; Name = "Malformed escape - extra space"}, | ||
|
|
@@ -807,11 +808,29 @@ Describe "Console host api tests" -Tag CI { | |
| { | ||
| @{InputObject = "$esc[31mabc"; Length = 3; Name = "Escape at start"} | ||
| @{InputObject = "$esc[31mabc$esc[0m"; Length = 3; Name = "Escape at start and end"} | ||
| @{InputObject = "${csi}31mabc"; Length = 3; Name = "C1 CSI at start"} | ||
| @{InputObject = "${csi}31mabc${csi}0m"; Length = 3; Name = "C1 CSI at start and end"} | ||
| @{InputObject = "abc${csi}m"; Length = 3; Name = "C1 CSI, no params"} | ||
| @{InputObject = "abc${csi}#{"; Length = 3; Name = "C1 CSI, XTPUSHSGR"} | ||
| @{InputObject = "abc${csi}#}"; Length = 3; Name = "C1 CSI, XTPOPSGR"} | ||
| @{InputObject = "abc${csi}#p"; Length = 3; Name = "C1 CSI, XTPUSHSGR (alias)"} | ||
| @{InputObject = "abc${csi}#q"; Length = 3; Name = "C1 CSI, XTPOPSGR (alias)"} | ||
| @{InputObject = "abc${esc}[0#p"; Length = 3; Name = "XTPUSHSGR, with param"} | ||
| @{InputObject = "${esc}[0;1#qabc"; Length = 3; Name = "XTPOPSGR, with multiple params"} | ||
| } | ||
| else | ||
| { | ||
| @{InputObject = "$esc[31mabc"; Length = 8; Name = "Escape at start - no virtual term support"} | ||
| @{InputObject = "$esc[31mabc$esc[0m"; Length = 12; Name = "Escape at start and end - no virtual term support"} | ||
| @{InputObject = "${csi}31mabc"; Length = 7; Name = "C1 CSI at start - no virtual term support"} | ||
| @{InputObject = "${csi}31mabc${csi}0m"; Length = 10; Name = "C1 CSI at start and end - no virtual term support"} | ||
| @{InputObject = "abc${csi}m"; Length = 5; Name = "C1 CSI, no params - no virtual term support"} | ||
| @{InputObject = "abc${csi}#{"; Length = 6; Name = "C1 CSI, XTPUSHSGR - no virtual term support"} | ||
| @{InputObject = "abc${csi}#}"; Length = 6; Name = "C1 CSI, XTPOPSGR - no virtual term support"} | ||
| @{InputObject = "abc${csi}#p"; Length = 6; Name = "C1 CSI, XTPUSHSGR (alias) - no virtual term support"} | ||
| @{InputObject = "abc${csi}#q"; Length = 6; Name = "C1 CSI, XTPOPSGR (alias) - no virtual term support"} | ||
| @{InputObject = "abc${esc}[0#p"; Length = 8; Name = "XTPUSHSGR, with param - no virtual term support"} | ||
| @{InputObject = "${esc}[0;1#qabc"; Length = 10; Name = "XTPOPSGR, with multiple params - no virtual term support"} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, actually, I don't know how to run the tests such that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| It "Should properly calculate buffer cell width of '<Name>'" -TestCases $testCases { | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use a temp variable in the cycle for performance instead of
offsetwhich is a reference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking at this, @iSazonov.
You made several performance-related recommendations:
offsetin the loop that skips control sequence parameters.str.Lengthinto a temporary local.offsetfor a larger portion of the function.It wasn't clear to me that these changes would improve things. I suspect the results of these changes might be small enought that they would be difficult to measure, so I haven't tried that, but I did look at the disassembly produced by the JIT compiler for an x64 Release version of the binary.
For the first case, there are more instructions and a little more stack and register pressure. Perhaps this would be made up for by eliminating a memory access; however the memory must be accessed eventually anyway, and that memory is on the stack, in the preceding frame--I don't expect it to leave L1 cache. So I don't know if it improves things, but I wouldn't guess it is much.
For the second, it looks like
str.Lengthhad already been put into a register, and the only thing the change does is create more stack and register pressure, so I think this could only actually make things worse (though I bet it would be difficult to measure).For the third, it looks similar to (1), but maybe not quite so bad? But again, it doesn't look like a clear win to me.
You can see the source changes and associated disassembly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jazzdelightsme Thanks!
The method is not call another methods so runtime can optimize the code very efficient.
Nevertheless, we can do something. I propose to make this method local in
ControlSequenceLengthso that we get direct access to "offset" and "str" variables inControlSequenceLength.