Use fmt::Write instead of io::Write in write.rs.

It is common to represent a function as a String, and previously that
required re-validating the UTF-8 in a Vec<u8>. The fmt::Write trait
writes UTF-8 directly into a String, so no extra checking is required.

This also means we can implement Display for Function which gives it a
to_string() method. This makes the function_to_string() method
redundant, so delete it.

The functions in the write module are no longer generally useful, so
make the module private. The Display trait on Function is all we need.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-15 13:56:42 -07:00
parent 0b8bf530b0
commit b40a3495fe
4 changed files with 21 additions and 30 deletions

View File

@@ -6,7 +6,8 @@
use ir::{FunctionName, Signature, StackSlot, StackSlotData, JumpTable, JumpTableData,
DataFlowGraph, Layout};
use entity_map::{EntityMap, PrimaryEntityData};
use std::fmt::{self, Debug, Formatter};
use std::fmt::{self, Display, Debug, Formatter};
use write::write_function;
/// A function.
///
@@ -60,9 +61,14 @@ impl Function {
}
}
impl Debug for Function {
impl Display for Function {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
use write::function_to_string;
fmt.write_str(&function_to_string(self))
write_function(fmt, self)
}
}
impl Debug for Function {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write_function(fmt, self)
}
}