'Replace len(char*) by the equivalent call to strlen(),
len(Py_UNICODE) by the equivalent Py_UNICODE_strlen() and
len(known_builtin_type) by an equivalent C-API call.'

def _handle_simple_function_len(self, node, function, pos_args):

    if (len(pos_args) != 1):
        self._error_wrong_arg_count('len', node, pos_args, 1)
        return node
    arg = pos_args[0]
    if isinstance(arg, ExprNodes.CoerceToPyTypeNode):
        arg = arg.arg
    if arg.type.is_string:
        new_node = ExprNodes.PythonCapiCallNode(node.pos, 'strlen', self.Pyx_strlen_func_type, args=[arg], is_temp=node.is_temp, utility_code=UtilityCode.load_cached('IncludeStringH', 'StringTools.c'))
    elif arg.type.is_pyunicode_ptr:
        new_node = ExprNodes.PythonCapiCallNode(node.pos, '__Pyx_Py_UNICODE_strlen', self.Pyx_Py_UNICODE_strlen_func_type, args=[arg], is_temp=node.is_temp)
    elif arg.type.is_memoryviewslice:
        func_type = PyrexTypes.CFuncType(PyrexTypes.c_size_t_type, [PyrexTypes.CFuncTypeArg('memoryviewslice', arg.type, None)], nogil=True)
        new_node = ExprNodes.PythonCapiCallNode(node.pos, '__Pyx_MemoryView_Len', func_type, args=[arg], is_temp=node.is_temp)
    elif arg.type.is_pyobject:
        cfunc_name = self._map_to_capi_len_function(arg.type)
        if (cfunc_name is None):
            arg_type = arg.type
            if ((arg_type.is_extension_type or arg_type.is_builtin_type) and (arg_type.entry.qualified_name in self._ext_types_with_pysize)):
                cfunc_name = 'Py_SIZE'
            else:
                return node
        arg = arg.as_none_safe_node("object    of    type    'NoneType'    has    no    len()")
        new_node = ExprNodes.PythonCapiCallNode(node.pos, cfunc_name, self.PyObject_Size_func_type, args=[arg], is_temp=node.is_temp)
    elif arg.type.is_unicode_char:
        return ExprNodes.IntNode(node.pos, value='1', constant_result=1, type=node.type)
    else:
        return node
    if (node.type not in (PyrexTypes.c_size_t_type, PyrexTypes.c_py_ssize_t_type)):
        new_node = new_node.coerce_to(node.type, self.current_env())
    return new_node
