Skip to content

Commit a5aa8a0

Browse files
authored
Merge pull request swiftlang#2626 from 3405691582/PleaseAvoidMallocIntrospection
[CF] Avoid using malloc introspection.
2 parents 8a86bf7 + 74cd0cf commit a5aa8a0

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

CoreFoundation/Collections.subproj/CFBasicHash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14421442
if (ht->bits.keys_offset) size += sizeof(CFBasicHashValue *);
14431443
if (ht->bits.counts_offset) size += sizeof(void *);
14441444
if (__CFBasicHashHasHashCache(ht)) size += sizeof(uintptr_t *);
1445+
#if ENABLE_MEMORY_COUNTERS || ENABLE_DTRACE_PROBES
14451446
if (total) {
14461447
CFIndex num_buckets = __CFBasicHashTableSizes[ht->bits.num_buckets_idx];
14471448
if (0 < num_buckets) {
@@ -1451,6 +1452,9 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14511452
if (__CFBasicHashHasHashCache(ht)) size += malloc_size(__CFBasicHashGetHashes(ht));
14521453
}
14531454
}
1455+
#else
1456+
(void)total;
1457+
#endif
14541458
return size;
14551459
}
14561460

CoreFoundation/Collections.subproj/CFStorage.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,21 +1366,6 @@ static void __CFStorageApplyNodeBlock(CFStorageRef storage, void (^block)(CFStor
13661366
__CFStorageApplyNodeBlockInterior(storage, &storage->rootNode, block);
13671367
}
13681368

1369-
static CFIndex __CFStorageEstimateTotalAllocatedSize(CFStorageRef storage) __attribute__((unused));
1370-
static CFIndex __CFStorageEstimateTotalAllocatedSize(CFStorageRef storage) {
1371-
__block CFIndex nodeResult = 0;
1372-
__block CFIndex contentsResult = 0;
1373-
__CFStorageApplyNodeBlock(storage, ^(CFStorageRef storage, CFStorageNode *node) {
1374-
if (node != &storage->rootNode) {
1375-
nodeResult += malloc_size(node);
1376-
if (node->isLeaf && node->info.leaf.memory != NULL) {
1377-
contentsResult += malloc_size(node->info.leaf.memory);
1378-
}
1379-
}
1380-
});
1381-
return nodeResult + contentsResult;
1382-
}
1383-
13841369
void __CFStorageSetAlwaysFrozen(CFStorageRef storage, bool alwaysFrozen) {
13851370
storage->alwaysFrozen = alwaysFrozen;
13861371
}

0 commit comments

Comments
 (0)