Skip to content

Simplify nil-checking in arc.mm:setObjectHasWeakRefs() #368

@cmpwi

Description

@cmpwi

Line 779 in setObjectHasWeakRefs() performs the following check:

if (obj && cls && objc_test_class_flag(cls, objc_class_flag_fast_arc))

Immediately below on line 782, obj is tested again:

if (obj)

In between the two checks, obj is not modified in any (observable) way. The surrounding body looks like this:

static BOOL setObjectHasWeakRefs(id obj)
{
	BOOL isGlobalObject = isPersistentObject(obj);
	Class cls = isGlobalObject ? Nil : obj->isa;
	if (obj && cls && objc_test_class_flag(cls, objc_class_flag_fast_arc))
	{
		uintptr_t *refCount = ((uintptr_t*)obj) - 1;
		if (obj)
		{
			<...>

Would it make sense to remove the second seemingly unnecessary check for obj? Stylistically, this would also remove one indentation level, which is (in my opinion) also desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions