Merge branch 'master' into 'master'

Avoid allocating temporary Strings in Display implementations

See merge request redox-os/termion!168
This commit is contained in:
Jeremy Soller 2020-01-20 16:18:50 +00:00
commit 250fb95a9c
2 changed files with 8 additions and 7 deletions

View File

@ -11,6 +11,7 @@ cache:
build:linux:stable: build:linux:stable:
stage: build stage: build
script: script:
- rustup update stable
- cargo +stable build --verbose - cargo +stable build --verbose
build:linux: build:linux:
@ -27,13 +28,13 @@ test:linux:stable:
- build:linux:stable - build:linux:stable
script: script:
- rustup update stable - rustup update stable
- cargo +stable test --verbose - script -c "cargo +stable test --verbose"
test:linux: test:linux:
stage: test stage: test
dependencies: dependencies:
- build:linux - build:linux
script: cargo +nightly test --verbose script: script -c "cargo +nightly test --verbose"
test:redox: test:redox:
stage: test stage: test

View File

@ -50,7 +50,7 @@ impl Default for Goto {
impl fmt::Display for Goto { impl fmt::Display for Goto {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
debug_assert!(self != &Goto(0, 0), "Goto is one-based."); debug_assert!(self != &Goto(0, 0), "Goto is one-based.");
f.write_str(&String::from(*self)) write!(f, "\x1B[{};{}H", self.1, self.0)
} }
} }
@ -67,7 +67,7 @@ impl From<Left> for String {
impl fmt::Display for Left { impl fmt::Display for Left {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&String::from(*self)) write!(f, "\x1B[{}D", self.0)
} }
} }
@ -84,7 +84,7 @@ impl From<Right> for String {
impl fmt::Display for Right { impl fmt::Display for Right {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&String::from(*self)) write!(f, "\x1B[{}C", self.0)
} }
} }
@ -101,7 +101,7 @@ impl From<Up> for String {
impl fmt::Display for Up { impl fmt::Display for Up {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&String::from(*self)) write!(f, "\x1B[{}A", self.0)
} }
} }
@ -118,7 +118,7 @@ impl From<Down> for String {
impl fmt::Display for Down { impl fmt::Display for Down {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&String::from(*self)) write!(f, "\x1B[{}B", self.0)
} }
} }