From dee722ce4fc86991b9bbccfc87d58b7db37d7623 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 18 May 2019 13:54:47 -0400 Subject: [PATCH] runtime_loader: Optimize a special case of get_nearest_symbol. If the caller does not want the symbol name/address/etc., we don't need to spend the time finding it, and can just return after finding the image. Change-Id: I138f8bd4071ffc25738dac4d6c0c6d3fe25edf1c Reviewed-on: https://review.haiku-os.org/c/1461 Reviewed-by: Adrien Destugues --- src/system/runtime_loader/elf.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index 916ed445cf..97855be79b 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -822,6 +822,18 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID, if (image == NULL) return B_BAD_VALUE; + if (_imageID != NULL) + *_imageID = image->id; + if (_imagePath != NULL) + *_imagePath = image->path; + if (_imageName != NULL) + *_imageName = image->name; + + // If the caller does not want the actual symbol name, only the image, + // we can just return immediately. + if (_symbolName == NULL && _type == NULL && _location == NULL) + return B_OK; + bool exactMatch = false; elf_sym* foundSymbol = NULL; addr_t foundLocation = (addr_t)NULL; @@ -845,12 +857,6 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID, } } - if (_imageID != NULL) - *_imageID = image->id; - if (_imagePath != NULL) - *_imagePath = image->path; - if (_imageName != NULL) - *_imageName = image->name; if (_exactMatch != NULL) *_exactMatch = exactMatch;