Files
Bubberstation/code/datums/components/shovel_hands.dm
SkyratBot 067188d366 [MIRROR] Micro-optimize qdel by only permitting one parameter [MDB IGNORE] (#25889)
* Micro-optimize qdel by only permitting one parameter (#80628)

Productionizes #80615.

The core optimization is this:

```patch
-	var/hint = to_delete.Destroy(arglist(args.Copy(2))) // Let our friend know they're about to get fucked up.
+	var/hint = to_delete.Destroy(force) // Let our friend know they're about to get fucked up.
```

We avoid a heap allocation in the form of copying the args over to a new
list. A/B testing shows this results in 33% better overtime, and in a
real round shaving off a full second of self time and 0.4 seconds of
overtime--both of these would be doubled in the event this is merged as
the new proc was only being run 50% of the time.

* Micro-optimize qdel by only permitting one parameter

---------

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2023-12-29 14:41:12 +00:00

43 lines
1.4 KiB
Plaintext

/// This component lets mobs dig up the floor with their bare hands
/datum/component/shovel_hands
dupe_mode = COMPONENT_DUPE_SOURCES
/// It's a lie, they're actually just using a shovel
var/obj/item/shovel/internal_shovel
/datum/component/shovel_hands/Initialize()
. = ..()
if (!isliving(parent))
return COMPONENT_INCOMPATIBLE
internal_shovel = new(null)
RegisterSignal(internal_shovel, COMSIG_QDELETING, PROC_REF(shovel_destroyed))
/datum/component/shovel_hands/RegisterWithParent()
. = ..()
RegisterSignals(parent, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_HOSTILE_PRE_ATTACKINGTARGET), PROC_REF(dig))
/datum/component/shovel_hands/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_HOSTILE_PRE_ATTACKINGTARGET))
return ..()
/datum/component/shovel_hands/Destroy(force)
if (internal_shovel)
UnregisterSignal(internal_shovel, COMSIG_QDELETING)
QDEL_NULL(internal_shovel)
return ..()
/// Called when you click on literally anything with your hands
/datum/component/shovel_hands/proc/dig(mob/living/mole, atom/target)
SIGNAL_HANDLER
if (!isopenturf(target))
return
INVOKE_ASYNC(target, TYPE_PROC_REF(/atom, attackby), internal_shovel, mole)
return COMPONENT_CANCEL_ATTACK_CHAIN
/// Don't know how the fuck this happened but I guess you can't dig any more
/datum/component/shovel_hands/proc/shovel_destroyed(atom/shovel)
SIGNAL_HANDLER
UnregisterSignal(shovel, COMSIG_QDELETING)
qdel(src)