Skip to content

Commit

Permalink
[wpiutil] DataLog.addSchema(): Don't add into a set view (#5829)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Oct 27, 2023
1 parent 2ab4fcb commit b91317f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void resume() {
* @return True if schema already registered
*/
public boolean hasSchema(String name) {
return m_schemaSet.contains(name);
return m_schemaMap.containsKey(name);
}

/**
Expand All @@ -134,7 +134,7 @@ public boolean hasSchema(String name) {
* @param timestamp Time stamp (may be 0 to indicate now)
*/
public void addSchema(String name, String type, byte[] schema, long timestamp) {
if (!m_schemaSet.add(name)) {
if (m_schemaMap.putIfAbsent(name, 1) != null) {
return;
}
DataLogJNI.addSchema(m_impl, name, type, schema, timestamp);
Expand Down Expand Up @@ -168,7 +168,7 @@ public void addSchema(String name, String type, byte[] schema) {
* @param timestamp Time stamp (may be 0 to indicate now)
*/
public void addSchema(String name, String type, String schema, long timestamp) {
if (!m_schemaSet.add(name)) {
if (m_schemaMap.putIfAbsent(name, 1) != null) {
return;
}
DataLogJNI.addSchemaString(m_impl, name, type, schema, timestamp);
Expand Down Expand Up @@ -506,5 +506,4 @@ private void addSchemaImpl(Struct<?> struct, long timestamp, Set<String> seen) {

private long m_impl;
private final ConcurrentMap<String, Integer> m_schemaMap = new ConcurrentHashMap<>();
private final Set<String> m_schemaSet = m_schemaMap.keySet();
}

0 comments on commit b91317f

Please sign in to comment.