Skip to content

Commit 3f4ea17

Browse files
Remove no longer used _withStackOrHeapBuffer and related utilities (#5291)
They were used in `Data` implementation but are no longer needed after FoundationEssentials.
1 parent 27283b7 commit 3f4ea17

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

Sources/CoreFoundation/include/ForSwiftFoundationOnly.h

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -483,69 +483,6 @@ typedef struct {
483483
bool onStack;
484484
} _ConditionalAllocationBuffer;
485485

486-
static inline bool _resizeConditionalAllocationBuffer(_ConditionalAllocationBuffer *_Nonnull buffer, size_t amt) {
487-
#if TARGET_OS_MAC
488-
size_t amount = malloc_good_size(amt);
489-
#else
490-
size_t amount = amt;
491-
#endif
492-
if (amount <= buffer->capacity) { return true; }
493-
void *newMemory;
494-
if (buffer->onStack) {
495-
newMemory = malloc(amount);
496-
if (newMemory == NULL) { return false; }
497-
memcpy(newMemory, buffer->memory, buffer->capacity);
498-
buffer->onStack = false;
499-
} else {
500-
newMemory = realloc(buffer->memory, amount);
501-
if (newMemory == NULL) { return false; }
502-
}
503-
if (newMemory == NULL) { return false; }
504-
buffer->memory = newMemory;
505-
buffer->capacity = amount;
506-
return true;
507-
}
508-
509-
#if TARGET_OS_WASI
510-
static inline bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
511-
_ConditionalAllocationBuffer buffer;
512-
buffer.capacity = amount;
513-
buffer.onStack = false;
514-
buffer.memory = malloc(buffer.capacity);
515-
if (buffer.memory == NULL) { return false; }
516-
applier(&buffer);
517-
free(buffer.memory);
518-
return true;
519-
}
520-
#else
521-
static inline bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
522-
_ConditionalAllocationBuffer buffer;
523-
#if TARGET_OS_MAC
524-
buffer.capacity = malloc_good_size(amount);
525-
#else
526-
buffer.capacity = amount;
527-
#endif
528-
buffer.onStack = (_CFIsMainThread() != 0 ? buffer.capacity < 2048 : buffer.capacity < 512);
529-
#if TARGET_OS_WIN32
530-
buffer.memory = buffer.onStack ? _alloca(buffer.capacity) : malloc(buffer.capacity);
531-
#else
532-
buffer.memory = buffer.onStack ? alloca(buffer.capacity) : malloc(buffer.capacity);
533-
#endif
534-
if (buffer.memory == NULL) { return false; }
535-
applier(&buffer);
536-
if (!buffer.onStack) {
537-
free(buffer.memory);
538-
}
539-
return true;
540-
}
541-
#endif
542-
543-
static inline bool _withStackOrHeapBufferWithResultInArguments(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(void *_Nonnull memory, size_t capacity, bool onStack)) {
544-
return _withStackOrHeapBuffer(amount, ^(_ConditionalAllocationBuffer *buffer) {
545-
applier(buffer->memory, buffer->capacity, buffer->onStack);
546-
});
547-
}
548-
549486
#pragma mark - Character Set
550487

551488
CF_CROSS_PLATFORM_EXPORT CFIndex __CFCharDigitValue(UniChar ch);

0 commit comments

Comments
 (0)