Speed up __sfileext initialization.
The internal uses don't need to actually initialize a mutex since they'll
never escape and don't need locking. It's a small saving, but easy.
Before:
BM_stdio_scanf_d 465 ns 465 ns 1507891
BM_stdio_scanf_maps 1836 ns 1836 ns 381082
BM_stdio_scanf_maps_baseline 846 ns 845 ns 830881
BM_stdio_scanf_s 419 ns 419 ns 1671979
After:
BM_stdio_scanf_d 434 ns 434 ns 1612930
BM_stdio_scanf_maps 1815 ns 1815 ns 386470
BM_stdio_scanf_maps_baseline 875 ns 873 ns 803304
BM_stdio_scanf_s 382 ns 382 ns 1833198
Bug: http://b/70862888
Test: ran tests, benchmarks
Change-Id: Ic8822aaca5d8ca1a73390089153d0fe35d91673e
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 0ff0785..517935b 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -159,24 +159,12 @@
#define _UB(fp) _EXT(fp)->_ub
#define _FLOCK(fp) _EXT(fp)->_lock
-#define _FILEEXT_INIT(fp) \
-do { \
- _UB(fp)._base = NULL; \
- _UB(fp)._size = 0; \
- WCIO_INIT(fp); \
- pthread_mutexattr_t attr; \
- pthread_mutexattr_init(&attr); \
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
- pthread_mutex_init(&_FLOCK(fp), &attr); \
- pthread_mutexattr_destroy(&attr); \
- _EXT(fp)->_caller_handles_locking = false; \
-} while (0)
-
-#define _FILEEXT_SETUP(f, fext) \
-do { \
- (f)->_ext._base = __BIONIC_CAST(reinterpret_cast, unsigned char*, fext); \
- _FILEEXT_INIT(f); \
-} while (0)
+#define _FILEEXT_SETUP(fp, fext) \
+ do { \
+ (fp)->_ext._base = __BIONIC_CAST(reinterpret_cast, unsigned char*, fext); \
+ memset(_EXT(fp), 0, sizeof(struct __sfileext)); \
+ _EXT(fp)->_caller_handles_locking = true; \
+ } while (0)
/*
* Android <= KitKat had getc/putc macros in <stdio.h> that referred