Skip to content

Commit 0afd832

Browse files
committed
Remove generics from Error by making fragment a String
This cause a reduction of IR lines emitted by the compiler of about 2% (using cargo llvm-lines), so this should improve compile times. I've seen using the parse example to check the produced binary size, but it's a small snippet I am not sure it calls a representative portion of the API surface. From a library perspective this is equivalent since the field is used only to be converted to string. In theory externally someone could use the field in the error to do things so it comes at a cost.
1 parent d3f638d commit 0afd832

File tree

4 files changed

+60
-62
lines changed

4 files changed

+60
-62
lines changed

src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,8 @@ impl error::Error for Error {
631631
}
632632

633633
#[doc(hidden)]
634-
impl<Pk, Ctx> From<miniscript::types::Error<Pk, Ctx>> for Error
635-
where
636-
Pk: MiniscriptKey,
637-
Ctx: ScriptContext,
638-
{
639-
fn from(e: miniscript::types::Error<Pk, Ctx>) -> Error { Error::TypeCheck(e.to_string()) }
634+
impl From<miniscript::types::Error> for Error {
635+
fn from(e: miniscript::types::Error) -> Error { Error::TypeCheck(e.to_string()) }
640636
}
641637

642638
#[doc(hidden)]

src/miniscript/types/extra_props.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl Property for ExtData {
860860
fn type_check_with_child<Pk, Ctx, C>(
861861
_fragment: &Terminal<Pk, Ctx>,
862862
mut _child: C,
863-
) -> Result<Self, Error<Pk, Ctx>>
863+
) -> Result<Self, Error>
864864
where
865865
C: FnMut(usize) -> Self,
866866
Pk: MiniscriptKey,
@@ -871,13 +871,13 @@ impl Property for ExtData {
871871

872872
/// Compute the type of a fragment assuming all the children of
873873
/// Miniscript have been computed already.
874-
fn type_check<Pk, Ctx>(fragment: &Terminal<Pk, Ctx>) -> Result<Self, Error<Pk, Ctx>>
874+
fn type_check<Pk, Ctx>(fragment: &Terminal<Pk, Ctx>) -> Result<Self, Error>
875875
where
876876
Ctx: ScriptContext,
877877
Pk: MiniscriptKey,
878878
{
879879
let wrap_err = |result: Result<Self, ErrorKind>| {
880-
result.map_err(|kind| Error { fragment: fragment.clone(), error: kind })
880+
result.map_err(|kind| Error { fragment_string: fragment.to_string(), error: kind })
881881
};
882882

883883
let ret = match *fragment {
@@ -888,13 +888,13 @@ impl Property for ExtData {
888888
Terminal::Multi(k, ref pks) | Terminal::MultiA(k, ref pks) => {
889889
if k == 0 {
890890
return Err(Error {
891-
fragment: fragment.clone(),
891+
fragment_string: fragment.to_string(),
892892
error: ErrorKind::ZeroThreshold,
893893
});
894894
}
895895
if k > pks.len() {
896896
return Err(Error {
897-
fragment: fragment.clone(),
897+
fragment_string: fragment.to_string(),
898898
error: ErrorKind::OverThreshold(k, pks.len()),
899899
});
900900
}
@@ -910,7 +910,7 @@ impl Property for ExtData {
910910
// only consumes 4 bytes from the stack.
911911
if t == absolute::LockTime::ZERO.into() {
912912
return Err(Error {
913-
fragment: fragment.clone(),
913+
fragment_string: fragment.to_string(),
914914
error: ErrorKind::InvalidTime,
915915
});
916916
}
@@ -919,7 +919,7 @@ impl Property for ExtData {
919919
Terminal::Older(t) => {
920920
if t == Sequence::ZERO || !t.is_relative_lock_time() {
921921
return Err(Error {
922-
fragment: fragment.clone(),
922+
fragment_string: fragment.to_string(),
923923
error: ErrorKind::InvalidTime,
924924
});
925925
}
@@ -975,20 +975,20 @@ impl Property for ExtData {
975975
Terminal::Thresh(k, ref subs) => {
976976
if k == 0 {
977977
return Err(Error {
978-
fragment: fragment.clone(),
978+
fragment_string: fragment.to_string(),
979979
error: ErrorKind::ZeroThreshold,
980980
});
981981
}
982982
if k > subs.len() {
983983
return Err(Error {
984-
fragment: fragment.clone(),
984+
fragment_string: fragment.to_string(),
985985
error: ErrorKind::OverThreshold(k, subs.len()),
986986
});
987987
}
988988

989989
let res = Self::threshold(k, subs.len(), |n| Ok(subs[n].ext));
990990

991-
res.map_err(|kind| Error { fragment: fragment.clone(), error: kind })
991+
res.map_err(|kind| Error { fragment_string: fragment.to_string(), error: kind })
992992
}
993993
};
994994
if let Ok(ref ret) = ret {

0 commit comments

Comments
 (0)