android_webview/tools/run_simpleperf.py
def ReplaceAddressesWithFunctionInfos(lines, address_function_pairs,
                                        lib_name):
    """Replaces the addresses with function names.

    Args:
      lines: A list of strings that may contain addresses.
      address_function_pairs: A list of pairs of (address, function_name).
      lib_name: The name of the WebView library.

    Returns:
      A list of strings with addresses replaced by function names.
    """

    logging.info('Replacing the HTML content with new function names...')

    # Note: Using a lenient pattern matching and a hashmap (dict) is much faster
    # than using a double loop (by the order of 1,000).
    # '+address' will be replaced by function name.
    address_function_dict = {
        '+' + k: html.escape(v, quote=False)
        for k, v in address_function_pairs
    }
    # Look behind the lib_name and '[' which will not be substituted. Note that
    # '+' is used in the pattern but will be removed.
    pattern = re.compile(r'(?<=' + lib_name + r'\[)\+([a-f0-9]+)(?=\])')

    def replace_fn(match):
      address = match.group(0)
      if address in address_function_dict:
        return address_function_dict[address]
      else:
        return address

    # Line-by-line assignment to avoid creating a temp list.
    for i, line in enumerate(lines):
      lines[i] = pattern.sub(replace_fn, line)

    logging.info('Replacing is done.')
    return lines
Replaces the addresses with function names.

    Args:
      lines: A list of strings that may contain addresses.
      address_function_pairs: A list of pairs of (address, function_name).
      lib_name: The name of the WebView library.

    Returns:
      A list of strings with addresses replaced by function names.
    
Replaces the addresses with function names.
Replaces the addresses with function names .
def ReplaceAddressesWithFunctionInfos(lines, address_function_pairs,
                                        lib_name):
    logging.info('Replacing the HTML content with new function names...')
    address_function_dict = {
        '+' + k: html.escape(v, quote=False)
        for k, v in address_function_pairs
    }
    pattern = re.compile(r'(?<=' + lib_name + r'\[)\+([a-f0-9]+)(?=\])')
    def replace_fn(match):
      address = match.group(0)
      if address in address_function_dict:
        return address_function_dict[address]
      else:
        return address
    for i, line in enumerate(lines):
      lines[i] = pattern.sub(replace_fn, line)
    logging.info('Replacing is done.')
    return lines
def ReplaceAddressesWithFunctionInfos ( lines , address_function_pairs , lib_name ) : logging . info ( 'Replacing the HTML content with new function names...' ) address_function_dict = { '+' + k : html . escape ( v , quote = False ) for k , v in address_function_pairs } pattern = re . compile ( r'(?<=' + lib_name + r'\[)\+([a-f0-9]+)(?=\])' ) def replace_fn ( match ) : address = match . group ( 0 ) if address in address_function_dict : return address_function_dict [ address ] else : return address for i , line in enumerate ( lines ) : lines [ i ] = pattern . sub ( replace_fn , line ) logging . info ( 'Replacing is done.' ) return lines
Replaces the addresses with function names.
Replaces the addresses with function names .
"""Replaces the addresses with function names.

    Args:
      lines: A list of strings that may contain addresses.
      address_function_pairs: A list of pairs of (address, function_name).
      lib_name: The name of the WebView library.

    Returns:
      A list of strings with addresses replaced by function names.
    """ # Note: Using a lenient pattern matching and a hashmap (dict) is much faster # than using a double loop (by the order of 1,000). # '+address' will be replaced by function name. # Look behind the lib_name and '[' which will not be substituted. Note that # '+' is used in the pattern but will be removed. # Line-by-line assignment to avoid creating a temp list.
A list of strings with addresses replaced by function names.
A list of strings with addresses replaced by function names .
lines
A list of strings that may contain addresses.
A list of strings that may contain addresses .
address_function_pairs
A list of pairs of (address, function_name).
A list of pairs of ( address function_name ) .
lib_name
The name of the WebView library.
The name of the WebView library .