If from is an instance of to, i.e., identical(S7_class(from), to) is TRUE (assuming from is an S7 object), then no dispatch should occur.
This is not (just) about efficiency. If there are convert() methods for downcasting to to, one of them will be called even if there is no need to downcast, potentially resulting in data being overwritten, or other weird things happening.
I'll also note that methods::as() is idempotent when to is class_any, but class_any is not allowed with convert(). Somewhat pedantic, but I thought it was worth mentioning.
If
fromis an instance ofto, i.e.,identical(S7_class(from), to)isTRUE(assumingfromis an S7 object), then no dispatch should occur.This is not (just) about efficiency. If there are
convert()methods for downcasting toto, one of them will be called even if there is no need to downcast, potentially resulting in data being overwritten, or other weird things happening.I'll also note that
methods::as()is idempotent whentoisclass_any, butclass_anyis not allowed withconvert(). Somewhat pedantic, but I thought it was worth mentioning.