You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2023/05/03 05:38:18 UTC

[GitHub] [camel] orpiske opened a new pull request, #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

orpiske opened a new pull request, #9982:
URL: https://github.com/apache/camel/pull/9982

   Signed-off-by: Otavio R. Piske <an...@gmail.com>


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske closed pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske closed pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base
URL: https://github.com/apache/camel/pull/9982


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532508522

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532567929

   @essobedo @davsclaus thanks for the great feedback folks!!! I kinda like Nicolas idea of using an EnumMap instead of a custom implementation. Let me go back to the drawing board, run some tests and try that instead. I'll mark this one as draft.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] essobedo commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532577741

   I quote the Javadoc https://docs.oracle.com/javase/8/docs/api/java/util/EnumMap.html:
   
   > Enum maps are represented internally as arrays. This representation is extremely compact and efficient.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] essobedo commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532632485

   Without very good reasons, I personally tend to prefer solutions based on JDK classes as they can always be improved in future versions of the JDK but if you really prefer having a fork of it, it is fine with me.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] essobedo commented on a diff in pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on code in PR #9982:
URL: https://github.com/apache/camel/pull/9982#discussion_r1183290909


##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {

Review Comment:
   ```suggestion
       public EnumArray(Class<T> keyType) {
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {

Review Comment:
   ```suggestion
   public final class EnumArray<T extends Enum<T>> {
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;

Review Comment:
   ```suggestion
           this.values = keyType.getEnumConstants();
           this.internalArray = new Object[values.length];
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry
+     * @param entry the entry to check for
+     * @return true if there is a payload or false otherwise
+     */
+    public boolean contains(T entry) {
+        Object payload = internalArray[entry.ordinal()];
+
+        return payload != null;
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @return the payload or false otherwise
+     */
+    public Object get(T entry) {
+        Objects.requireNonNull(entry, "The entry for a enum array cannot be null");
+
+        return internalArray[entry.ordinal()];
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @param clazz the class to cast the payload to
+     * @return the payload or false otherwise
+     * @param <K> the payload type
+     */
+    public <K> K get(T entry, Class<K> clazz) {
+        Object tmp = get(entry);
+
+        if (tmp != null) {
+            return clazz.cast(tmp);
+        }
+
+        return null;
+    }
+
+    /**
+     * Computes a new value for the entry if it's present on this instance
+     * @param entry the entry to compute the value for
+     * @param mappingFunction the mapping function that will provide the new value. It takes as a parameter the old value.
+     * @return the new value that was computed for this entry
+     */
+    public Object computeIfPresent(T entry, Function<Object, Object> mappingFunction) {
+        Object payload = get(entry);
+
+        if (payload != null) {
+            payload = mappingFunction.apply(payload);
+
+            set(entry, payload);
+        }
+
+        return payload;
+    }
+
+    /**
+     * Sets the payload for the given entry
+     * @param entry the entry to set the payload
+     * @param payload the payload
+     */
+    public void set(T entry, Object payload) {
+        internalArray[entry.ordinal()] = payload;

Review Comment:
   ```suggestion
           internalArray[Objects.requireNonNull(entry, "The entry for a enum array cannot be null").ordinal()] = payload;
   ```
   To be homogenous, we should check if it is null here too



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry

Review Comment:
   ```suggestion
        * Whether this array contains a payload (value) for the given entry
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry
+     * @param entry the entry to check for
+     * @return true if there is a payload or false otherwise
+     */
+    public boolean contains(T entry) {
+        Object payload = internalArray[entry.ordinal()];
+
+        return payload != null;
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @return the payload or false otherwise
+     */
+    public Object get(T entry) {
+        Objects.requireNonNull(entry, "The entry for a enum array cannot be null");
+
+        return internalArray[entry.ordinal()];
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @param clazz the class to cast the payload to
+     * @return the payload or false otherwise
+     * @param <K> the payload type
+     */
+    public <K> K get(T entry, Class<K> clazz) {
+        Object tmp = get(entry);
+
+        if (tmp != null) {
+            return clazz.cast(tmp);
+        }
+
+        return null;

Review Comment:
   ```suggestion
           return clazz.cast(get(entry));
   ```
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry
+     * @param entry the entry to check for
+     * @return true if there is a payload or false otherwise
+     */
+    public boolean contains(T entry) {
+        Object payload = internalArray[entry.ordinal()];
+
+        return payload != null;
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @return the payload or false otherwise
+     */
+    public Object get(T entry) {
+        Objects.requireNonNull(entry, "The entry for a enum array cannot be null");
+
+        return internalArray[entry.ordinal()];

Review Comment:
   ```suggestion
           return internalArray[Objects.requireNonNull(entry, "The entry for a enum array cannot be null").ordinal()];
   ```



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry
+     * @param entry the entry to check for
+     * @return true if there is a payload or false otherwise
+     */
+    public boolean contains(T entry) {
+        Object payload = internalArray[entry.ordinal()];
+
+        return payload != null;

Review Comment:
   ```suggestion
           return internalArray[entry.ordinal()] != null;
   ```
   
   Let's inline to avoid adding a local variable



##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {

Review Comment:
   Why not use `EnumMap` instead?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] essobedo commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532576404

   > -1 for enum map
   > 
   > A fixed Object[] array are much smaller - and the original optimization was for avoding Map and other types that are large, and take up extra memory per message/exchange.
   > 
   > And the lookup by ordinal value is a lot faster than a Map lookup by key.
   
   Internally an `EnumMap` uses an array, in fact it does more or less the same as this custom class


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532575062

   @davsclaus yeah, there can be some drawbacks. It may also suffer from the type check issue (which is why I created this custom implementation) ... but it's a small change to check. Let me take a quick look and see how it goes.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] davsclaus commented on a diff in pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #9982:
URL: https://github.com/apache/camel/pull/9982#discussion_r1183300670


##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {
+    private final Object[] internalArray;
+    private final T[] values;
+
+    /**
+     * Creates a new EnumArray with a fixed size determined by the length of values
+     * @param values the Enum values (as in Enum.values())
+     */
+    public EnumArray(T[] values) {
+        this.internalArray = new Object[values.length];
+        this.values = values;
+    }
+
+    /**
+     * Whether this arrau contains a payload (value) for the given entry
+     * @param entry the entry to check for
+     * @return true if there is a payload or false otherwise
+     */
+    public boolean contains(T entry) {
+        Object payload = internalArray[entry.ordinal()];
+
+        return payload != null;
+    }
+
+    /**
+     * Gets the payload for the given entry
+     * @param entry the entry to get the payload (must not be null)
+     * @return the payload or false otherwise
+     */
+    public Object get(T entry) {
+        Objects.requireNonNull(entry, "The entry for a enum array cannot be null");

Review Comment:
   This just adds unnessasary overhead on a hot path - the old code did not need this check



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske commented on a diff in pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9982:
URL: https://github.com/apache/camel/pull/9982#discussion_r1183323861


##########
core/camel-support/src/main/java/org/apache/camel/support/EnumArray.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.support;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * This class provides an array-based structure used to store payloads associated with enums. This is
+ * used in the hot path of the core code to allow access to those payloads with constant time and low
+ * memory overhead.
+ *
+ * This data-structure is meant for internal usage of the Camel Core and is not meant for users.
+ * @param <T>
+ */
+public final class EnumArray<T extends Enum<?>> {

Review Comment:
   @essobedo 🤔 I like your idea. Let me give it a try and see if we can skip the ssc issue with it and it may be a better implementation. 



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] davsclaus commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532572594

   -1  for enum map
   
   A fixed Object[] array are much smaller - and the original optimization was for avoding Map and other types that are large, and take up extra memory per message/exchange.
   
   And the lookup by ordinal value is a lot faster than a Map lookup by a hashed key. 
   
   


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532474770

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :warning: Please note that the changes on this PR may be **tested automatically**. 
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532514669

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532660103

   Folks, I am closing this one. I believe we all converged on #9984 (EnumMap one) as the solution. Thanks for the reviews and comments!!!


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532540389

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] orpiske commented on pull request #9982: CAMEL-19058: added a new wrapper for the enum array pattern used throughout the code base

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9982:
URL: https://github.com/apache/camel/pull/9982#issuecomment-1532620874

   Folks, so, I tested using an `EnumMap` and it does not trigger the type check issue. The performance is roughly the same for both, and the internal implementation of `EnumMap` is pretty much the same one as we have here (with a much better interface). 
   
   @davsclaus @essobedo I am not strongly in favor of any solution, but I feel the `EnumMap` one might be a better choice. 
   
   Even if there is some performance impact, I think we can offset that by fixing other parts of the code that are still being affected by the JDK issue. 


-- 
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: commits-unsubscribe@camel.apache.org

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