Skip to content

Commit edf8e58

Browse files
author
Vladimir Kotal
authored
cleanup Eftar issues found by LGTM (#3809)
* cleanup issues found by LGTM * fix style
1 parent 4ceb1b9 commit edf8e58

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/EftarFile.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static class Node {
5757
public Map<Long, Node> children;
5858
public long tagOffset;
5959
public long childOffset;
60-
public long myOffset;
6160

6261
Node(long hash, String tag) {
6362
this.hash = hash;
@@ -87,7 +86,7 @@ public static long myHash(String name) {
8786
n = 100;
8887
}
8988
for (int i = 0; i < n; i++) {
90-
hash = (hash * 641 + name.charAt(i) * 2969 + hash << 6) % 9322397;
89+
hash = (hash * 641L + name.charAt(i) * 2969 + hash << 6) % 9322397;
9190
}
9291
return hash;
9392
}
@@ -97,28 +96,28 @@ private void write(Node n, DataOutputStream out) throws IOException {
9796
out.write(n.tag.getBytes());
9897
offset += n.tag.length();
9998
}
100-
for (Node childnode : n.children.values()) {
101-
out.writeLong(childnode.hash);
102-
if (childnode.children.size() > 0) {
103-
out.writeShort((short) (childnode.childOffset - offset));
104-
out.writeShort((short) childnode.children.size());
99+
for (Node childNode : n.children.values()) {
100+
out.writeLong(childNode.hash);
101+
if (childNode.children.size() > 0) {
102+
out.writeShort((short) (childNode.childOffset - offset));
103+
out.writeShort((short) childNode.children.size());
105104
} else {
106105
out.writeShort(0);
107-
if (childnode.tag == null) {
106+
if (childNode.tag == null) {
108107
out.writeShort((short) 0);
109108
} else {
110-
out.writeShort((short) childnode.tag.length());
109+
out.writeShort((short) childNode.tag.length());
111110
}
112111
}
113-
if (childnode.tag == null) {
112+
if (childNode.tag == null) {
114113
out.writeShort(0);
115114
} else {
116-
out.writeShort((short) (childnode.tagOffset - offset));
115+
out.writeShort((short) (childNode.tagOffset - offset));
117116
}
118117
offset += RECORD_LENGTH;
119118
}
120-
for (Node childnode : n.children.values()) {
121-
write(childnode, out);
119+
for (Node childNode : n.children.values()) {
120+
write(childNode, out);
122121
}
123122
}
124123

@@ -131,7 +130,7 @@ private void traverse(Node n) {
131130
}
132131
if (n.children.size() > 0) {
133132
n.childOffset = offset;
134-
offset += (RECORD_LENGTH * n.children.size());
133+
offset += ((long) RECORD_LENGTH * n.children.size());
135134
} else {
136135
n.childOffset = 0;
137136
}
@@ -143,9 +142,8 @@ private void traverse(Node n) {
143142
/**
144143
* Reads the input into interim representation. Can be called multiple times.
145144
* @param descriptions set of PathDescription
146-
* @throws IOException
147145
*/
148-
private void readInput(Set<PathDescription> descriptions) throws IOException {
146+
private void readInput(Set<PathDescription> descriptions) {
149147
if (root == null) {
150148
root = new Node(1, null);
151149
}
@@ -163,8 +161,7 @@ private void readInput(Set<PathDescription> descriptions) throws IOException {
163161
public void write(String outPath) throws IOException {
164162
offset = RECORD_LENGTH;
165163
traverse(root);
166-
try (DataOutputStream out = new DataOutputStream(
167-
new BufferedOutputStream(new FileOutputStream(outPath)))) {
164+
try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outPath)))) {
168165
out.writeLong(0x5e33);
169166
out.writeShort(RECORD_LENGTH);
170167
out.writeShort(root.children.size());

opengrok-indexer/src/main/java/org/opengrok/indexer/web/EftarFileReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ private FNode binarySearch(long start, int len, long hash) throws IOException {
9090
int e = len;
9191
while (b <= e) {
9292
int m = (b + e) / 2;
93-
f.seek(start + m * EftarFile.RECORD_LENGTH);
93+
f.seek(start + (long) m * EftarFile.RECORD_LENGTH);
9494
long mhash = f.readLong();
9595
if (hash > mhash) {
9696
b = m + 1;
9797
} else if (hash < mhash) {
9898
e = m - 1;
9999
} else {
100-
return new FNode(mhash, f.getFilePointer() - 8L, f.readUnsignedShort(), f.readUnsignedShort(), f.readUnsignedShort());
100+
return new FNode(mhash, f.getFilePointer() - 8L, f.readUnsignedShort(), f.readUnsignedShort(),
101+
f.readUnsignedShort());
101102
}
102103
}
103104
return null;

0 commit comments

Comments
 (0)