[all-commits] [llvm/llvm-project] 07eb82: Add _LIBCPP_BUILTIN_CONSTANT_P support.

Martijn Vels via All-commits all-commits at lists.llvm.org
Wed Feb 26 08:04:54 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 07eb82fc06cc41a64d136d046e6b30565c3e5579
      https://github.com/llvm/llvm-project/commit/07eb82fc06cc41a64d136d046e6b30565c3e5579
  Author: Martijn Vels <mvels at google.com>
  Date:   2020-02-26 (Wed, 26 Feb 2020)

  Changed paths:
    M libcxx/include/__config

  Log Message:
  -----------
  Add _LIBCPP_BUILTIN_CONSTANT_P support.

Summary:
This change adds the macros _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT and _LIBCPP_BUILTIN_CONSTANT_P to detect compile time constants, and optimze the code accordingly.

A planned usage example:
The implementation of basic_string::assign() can short-cut a compile time known short string assignent into a fast and compact inlined assignment:

```
basic_string::assign(const value_type* __s) {
  if (_LIBCPP_BUILTIN_CONSTANT_P(__s[0]) && length(__s) < __min_cap) {
    copy(pointer(), _s, length(__s) + 1);
    set_size(length(__s));
  } else {
    // delegate / tail call out of line implementation
  }
}
```

Subscribers: christof, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D73732




More information about the All-commits mailing list