Skip to content

Commit

Permalink
avoid generic versions of raising function
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jan 8, 2022
1 parent 868cd6f commit 66745f2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ssz_serialization/codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ import
export
types

func raiseMalformedSszError*(T: type, msg: string) {.raisesssz, noinline, noreturn.} =
const typeName = name(T)
func reallyRaiseMalformedSszError(typeName, msg: string) {.
raisesssz, noinline, noreturn.} =
# `noinline` helps keep the C code tight on the happy path
# passing `typeName` in avoids generating generic copies of this function
raise (ref MalformedSszError)(msg: "SSZ " & typeName & ": " & msg)

template raiseMalformedSszError*(T: type, msg: string) =
const typeName = name(T)
reallyRaiseMalformedSszError(typeName, msg)

template raiseIncorrectSize*(T: type) =
raiseMalformedSszError(T, "incorrect size")

Expand Down

0 comments on commit 66745f2

Please sign in to comment.