From 1a56a26f1169da432de36016ee3d2f37c71b4eef Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 20 Dec 2017 08:53:49 -0800 Subject: 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 --- libc/stdio/stdio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libc/stdio/stdio.cpp') diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp index d6275569c..d3ac0436e 100644 --- a/libc/stdio/stdio.cpp +++ b/libc/stdio/stdio.cpp @@ -170,7 +170,10 @@ found: fp->_lb._base = nullptr; /* no line buffer */ fp->_lb._size = 0; - _FILEEXT_INIT(fp); + + memset(_EXT(fp), 0, sizeof(struct __sfileext)); + _FLOCK(fp) = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + _EXT(fp)->_caller_handles_locking = false; // Caller sets cookie, _read/_write etc. // We explicitly clear _seek and _seek64 to prevent subtle bugs. -- cgit v1.2.3