You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/15 17:53:33 UTC

[GitHub] [arrow] bkietz opened a new pull request #10726: [C++] Remove compile time parsing from EnumType

bkietz opened a new pull request #10726:
URL: https://github.com/apache/arrow/pull/10726


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] bkietz closed pull request #10726: ARROW-13346: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
bkietz closed pull request #10726:
URL: https://github.com/apache/arrow/pull/10726


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] removed a comment on pull request #10726: ARROW-13347: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
github-actions[bot] removed a comment on pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#issuecomment-880897795


   <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
   -->
   
   Thanks for opening a pull request!
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on JIRA? https://issues.apache.org/jira/browse/ARROW
   
   Opening JIRAs ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename pull request title in the following format?
   
       ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/arrow/pulls/)
     * [Contribution Guidelines - How to contribute patches](https://arrow.apache.org/docs/developers/contributing.html#how-to-contribute-patches)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #10726: ARROW-13347: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#issuecomment-880899581


   https://issues.apache.org/jira/browse/ARROW-13347


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #10726: ARROW-13346: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#issuecomment-881010975


   https://issues.apache.org/jira/browse/ARROW-13346


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm commented on a change in pull request #10726: ARROW-13347: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
lidavidm commented on a change in pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#discussion_r670696529



##########
File path: cpp/src/arrow/util/enum.h
##########
@@ -43,68 +42,51 @@ constexpr bool CaseInsensitiveEquals(util::string_view l, util::string_view r) {
   return l.size() == r.size() && CaseInsensitiveEquals(l.data(), r.data(), l.size());
 }
 
-constexpr const char* SkipWhitespace(const char* raw) {
-  return *raw == '\0' || !IsSpace(*raw) ? raw : SkipWhitespace(raw + 1);
-}
+}  // namespace internal
 
-constexpr const char* SkipNonWhitespace(const char* raw) {
-  return *raw == '\0' || IsSpace(*raw) ? raw : SkipNonWhitespace(raw + 1);
-}
+template <int N>
+struct EnumStrings {
+  template <int M>
+  static constexpr bool assert_count() {
+    static_assert(M == N, "Incorrect number of enum strings provided");
+    return false;
+  }
 
-constexpr size_t TokenSize(const char* token_start) {
-  return SkipNonWhitespace(token_start) - token_start;
-}
+  template <typename... Strs>
+  constexpr EnumStrings(const Strs&... strs)  // NOLINT runtime/explicit
+      : dummy_{assert_count<sizeof...(Strs)>()}, strings_{util::string_view(strs)...} {}
 
-constexpr size_t NextTokenStart(const char* raw, size_t token_start) {
-  return SkipWhitespace(SkipNonWhitespace(raw + token_start)) - raw;
-}
+  constexpr int GetIndex(util::string_view repr, int i = 0) const {
+    return i == N ? -1
+                  : internal::CaseInsensitiveEquals(strings_[i], repr)
+                        ? i
+                        : GetIndex(repr, i + 1);
+  }
 
-template <typename Raw, size_t... Offsets>
-struct EnumTypeImpl {
-  static constexpr int kSize = sizeof...(Offsets);
+  using value_type = util::string_view;
+  using const_iterator = const util::string_view*;
 
-  static constexpr util::string_view kValueStrs[sizeof...(Offsets)] = {
-      {Raw::kValues + Offsets, TokenSize(Raw::kValues + Offsets)}...};
+  constexpr int size() const { return N; }
+  constexpr const util::string_view* data() const { return strings_; }
+  constexpr const_iterator begin() const { return data(); }
+  constexpr const_iterator end() const { return begin() + size(); }
+  constexpr util::string_view operator[](int i) const { return strings_[i]; }
 
-  static constexpr int GetIndex(util::string_view repr, int i = 0) {
-    return i == kSize
-               ? -1
-               : CaseInsensitiveEquals(kValueStrs[i], repr) ? i : GetIndex(repr, i + 1);
-  }
+  bool dummy_;
+  util::string_view strings_[N];  // NOLINT modernize

Review comment:
       We can't use std::array since its methods aren't constexpr until C++17?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm commented on a change in pull request #10726: ARROW-13347: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
lidavidm commented on a change in pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#discussion_r670700559



##########
File path: cpp/src/arrow/util/enum.h
##########
@@ -43,68 +42,51 @@ constexpr bool CaseInsensitiveEquals(util::string_view l, util::string_view r) {
   return l.size() == r.size() && CaseInsensitiveEquals(l.data(), r.data(), l.size());
 }
 
-constexpr const char* SkipWhitespace(const char* raw) {
-  return *raw == '\0' || !IsSpace(*raw) ? raw : SkipWhitespace(raw + 1);
-}
+}  // namespace internal
 
-constexpr const char* SkipNonWhitespace(const char* raw) {
-  return *raw == '\0' || IsSpace(*raw) ? raw : SkipNonWhitespace(raw + 1);
-}
+template <int N>
+struct EnumStrings {
+  template <int M>
+  static constexpr bool assert_count() {
+    static_assert(M == N, "Incorrect number of enum strings provided");
+    return false;
+  }
 
-constexpr size_t TokenSize(const char* token_start) {
-  return SkipNonWhitespace(token_start) - token_start;
-}
+  template <typename... Strs>
+  constexpr EnumStrings(const Strs&... strs)  // NOLINT runtime/explicit
+      : dummy_{assert_count<sizeof...(Strs)>()}, strings_{util::string_view(strs)...} {}
 
-constexpr size_t NextTokenStart(const char* raw, size_t token_start) {
-  return SkipWhitespace(SkipNonWhitespace(raw + token_start)) - raw;
-}
+  constexpr int GetIndex(util::string_view repr, int i = 0) const {
+    return i == N ? -1
+                  : internal::CaseInsensitiveEquals(strings_[i], repr)
+                        ? i
+                        : GetIndex(repr, i + 1);
+  }
 
-template <typename Raw, size_t... Offsets>
-struct EnumTypeImpl {
-  static constexpr int kSize = sizeof...(Offsets);
+  using value_type = util::string_view;
+  using const_iterator = const util::string_view*;
 
-  static constexpr util::string_view kValueStrs[sizeof...(Offsets)] = {
-      {Raw::kValues + Offsets, TokenSize(Raw::kValues + Offsets)}...};
+  constexpr int size() const { return N; }
+  constexpr const util::string_view* data() const { return strings_; }
+  constexpr const_iterator begin() const { return data(); }
+  constexpr const_iterator end() const { return begin() + size(); }
+  constexpr util::string_view operator[](int i) const { return strings_[i]; }
 
-  static constexpr int GetIndex(util::string_view repr, int i = 0) {
-    return i == kSize
-               ? -1
-               : CaseInsensitiveEquals(kValueStrs[i], repr) ? i : GetIndex(repr, i + 1);
-  }
+  bool dummy_;
+  util::string_view strings_[N];  // NOLINT modernize

Review comment:
       (I feel like I've asked you this before upon reflection…)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #10726: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#issuecomment-880897795


   <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
   -->
   
   Thanks for opening a pull request!
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on JIRA? https://issues.apache.org/jira/browse/ARROW
   
   Opening JIRAs ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename pull request title in the following format?
   
       ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/arrow/pulls/)
     * [Contribution Guidelines - How to contribute patches](https://arrow.apache.org/docs/developers/contributing.html#how-to-contribute-patches)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] bkietz commented on a change in pull request #10726: ARROW-13347: [C++] Remove compile time parsing from EnumType

Posted by GitBox <gi...@apache.org>.
bkietz commented on a change in pull request #10726:
URL: https://github.com/apache/arrow/pull/10726#discussion_r670701550



##########
File path: cpp/src/arrow/util/enum.h
##########
@@ -43,68 +42,51 @@ constexpr bool CaseInsensitiveEquals(util::string_view l, util::string_view r) {
   return l.size() == r.size() && CaseInsensitiveEquals(l.data(), r.data(), l.size());
 }
 
-constexpr const char* SkipWhitespace(const char* raw) {
-  return *raw == '\0' || !IsSpace(*raw) ? raw : SkipWhitespace(raw + 1);
-}
+}  // namespace internal
 
-constexpr const char* SkipNonWhitespace(const char* raw) {
-  return *raw == '\0' || IsSpace(*raw) ? raw : SkipNonWhitespace(raw + 1);
-}
+template <int N>
+struct EnumStrings {
+  template <int M>
+  static constexpr bool assert_count() {
+    static_assert(M == N, "Incorrect number of enum strings provided");
+    return false;
+  }
 
-constexpr size_t TokenSize(const char* token_start) {
-  return SkipNonWhitespace(token_start) - token_start;
-}
+  template <typename... Strs>
+  constexpr EnumStrings(const Strs&... strs)  // NOLINT runtime/explicit
+      : dummy_{assert_count<sizeof...(Strs)>()}, strings_{util::string_view(strs)...} {}
 
-constexpr size_t NextTokenStart(const char* raw, size_t token_start) {
-  return SkipWhitespace(SkipNonWhitespace(raw + token_start)) - raw;
-}
+  constexpr int GetIndex(util::string_view repr, int i = 0) const {
+    return i == N ? -1
+                  : internal::CaseInsensitiveEquals(strings_[i], repr)
+                        ? i
+                        : GetIndex(repr, i + 1);
+  }
 
-template <typename Raw, size_t... Offsets>
-struct EnumTypeImpl {
-  static constexpr int kSize = sizeof...(Offsets);
+  using value_type = util::string_view;
+  using const_iterator = const util::string_view*;
 
-  static constexpr util::string_view kValueStrs[sizeof...(Offsets)] = {
-      {Raw::kValues + Offsets, TokenSize(Raw::kValues + Offsets)}...};
+  constexpr int size() const { return N; }
+  constexpr const util::string_view* data() const { return strings_; }
+  constexpr const_iterator begin() const { return data(); }
+  constexpr const_iterator end() const { return begin() + size(); }
+  constexpr util::string_view operator[](int i) const { return strings_[i]; }
 
-  static constexpr int GetIndex(util::string_view repr, int i = 0) {
-    return i == kSize
-               ? -1
-               : CaseInsensitiveEquals(kValueStrs[i], repr) ? i : GetIndex(repr, i + 1);
-  }
+  bool dummy_;
+  util::string_view strings_[N];  // NOLINT modernize

Review comment:
       correct




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org