diff options
author | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-05-13 10:59:32 (GMT) |
---|---|---|
committer | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-05-13 10:59:32 (GMT) |
commit | aafa141509243b40b852ef16b1810de96659d658 (patch) | |
tree | 7d3c567492691cb27263bba89917b63a8a24add2 /generic/tclObj.c | |
parent | d6ed36f1345762e1090f0c82aa5c48e05fbdbb26 (diff) | |
download | tcl-aafa141509243b40b852ef16b1810de96659d658.zip tcl-aafa141509243b40b852ef16b1810de96659d658.tar.gz tcl-aafa141509243b40b852ef16b1810de96659d658.tar.bz2 |
Add TclRelaxRefCount, and also try to take the fast path more often in byte-compiled [lindex].
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r-- | generic/tclObj.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c index 0c9c405..97e262b 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3707,7 +3707,7 @@ Tcl_IncrRefCount( * Decrements the reference count of the object. * * Results: - * None. + * The storage for objPtr may be freed. * *---------------------------------------------------------------------- */ @@ -3725,6 +3725,28 @@ Tcl_DecrRefCount( /* *---------------------------------------------------------------------- * + * TclRelaxRefCount -- + * + * Decrement the refCount of objPtr without causing it to be freed if it + * drops from 1 to 0. This allows a function increment a refCount but + * then decrement it and still be able to pass return it to a caller, + * possibly with a refCount of 0. The caller must have previously + * incremented the refCount. + * + *---------------------------------------------------------------------- + */ +void +TclRelaxRefCount( + Tcl_Obj *objPtr) /* The object we are releasing a reference to. */ +{ + if (objPtr->refCount > 0) { + --objPtr->refCount; + } +} + +/* + *---------------------------------------------------------------------- + * * Tcl_IsShared -- * * Tests if the object has a ref count greater than one. |