Skip to content

Commit aba0cf1

Browse files
Remove unnecessary cloning location variable
1 parent e9d5726 commit aba0cf1

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

ballerina/modules/parser/lexer.bal

+10-10
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class Lexer {
5555
return {
5656
kind: T_EOF,
5757
value: "",
58-
location: self.currentLocation.clone()
58+
location: self.currentLocation
5959
};
6060
}
6161
int tokenTag = -1;
@@ -78,14 +78,14 @@ public class Lexer {
7878
}
7979

8080
isolated function readSeparatorToken(string:Char char) returns Token? {
81-
Location location = self.currentLocation.clone();
81+
Location location = self.currentLocation;
8282
_ = self.readNextChar();
8383
int kind = getTokenType(char);
8484
return getToken(char, kind, location);
8585
}
8686

8787
isolated function readSpecialCharacterToken(string:Char char) returns Token {
88-
Location location = self.currentLocation.clone();
88+
Location location = self.currentLocation;
8989
_ = self.readNextChar();
9090
int kind = getTokenType(char);
9191
return getToken(char, kind, location);
@@ -101,7 +101,7 @@ public class Lexer {
101101

102102
isolated function readSingleLineStringLiteral() returns Token|SyntaxError {
103103
string word = "";
104-
Location location = self.currentLocation.clone();
104+
Location location = self.currentLocation;
105105
_ = self.readNextChar(); // Consume first double quote character
106106

107107
string:Char? char = self.charReader.peek();
@@ -133,7 +133,7 @@ public class Lexer {
133133
}
134134

135135
isolated function readBlockStringLiteral() returns Token|SyntaxError {
136-
Location location = self.currentLocation.clone();
136+
Location location = self.currentLocation;
137137
string[] lines = [];
138138
string line = "";
139139
self.consumeIgnoreChars(3); // Consume first three double quote characters
@@ -234,7 +234,7 @@ public class Lexer {
234234
}
235235

236236
isolated function readNumericLiteral(string:Char firstChar) returns Token|SyntaxError {
237-
Location location = self.currentLocation.clone();
237+
Location location = self.currentLocation;
238238
string numeral = firstChar; // Passing first char to handle negative numbers.
239239
_ = self.readNextChar(); // Consume first char
240240
string:Char? character = self.charReader.peek();
@@ -306,7 +306,7 @@ public class Lexer {
306306
}
307307

308308
isolated function readCommentToken() returns Token|SyntaxError {
309-
Location location = self.currentLocation.clone();
309+
Location location = self.currentLocation;
310310
_ = self.readNextChar(); // Ignore first hash character
311311
string:Char? character = self.charReader.peek();
312312
string word = "#";
@@ -329,7 +329,7 @@ public class Lexer {
329329
}
330330

331331
isolated function readEllipsisToken() returns Token|SyntaxError {
332-
Location location = self.currentLocation.clone();
332+
Location location = self.currentLocation;
333333
string ellipsis = "";
334334
int i = 0;
335335
while i < 3 {
@@ -352,7 +352,7 @@ public class Lexer {
352352
}
353353

354354
isolated function readIdentifierToken(string:Char firstChar) returns Token|SyntaxError {
355-
Location location = self.currentLocation.clone();
355+
Location location = self.currentLocation;
356356
_ = self.readNextChar();
357357
check validateFirstChar(firstChar, self.currentLocation);
358358
string word = firstChar;
@@ -367,7 +367,7 @@ public class Lexer {
367367
if tokenTag >= WHITE_SPACE_TAG && tokenTag <= SPECIAL_CHARACTER_TAG {
368368
break;
369369
} else {
370-
Location charLocation = self.currentLocation.clone();
370+
Location charLocation = self.currentLocation;
371371
_ = self.readNextChar();
372372
check validateChar(char, charLocation);
373373
word += char;

ballerina/modules/parser/parser.bal

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Parser {
6161

6262
isolated function parseOperationWithType(RootOperationType operationType) returns Error? {
6363
Token token = check self.readNextNonSeparatorToken();
64-
Location location = token.location.clone();
64+
Location location = token.location;
6565
token = check self.peekNextNonSeparatorToken();
6666
string operationName = check getOperationNameFromToken(self);
6767
token = check self.peekNextNonSeparatorToken();
@@ -76,7 +76,7 @@ public class Parser {
7676

7777
isolated function parseFragment() returns Error? {
7878
Token token = check self.readNextNonSeparatorToken(); // fragment keyword already validated
79-
Location location = token.location.clone();
79+
Location location = token.location;
8080

8181
token = check self.readNextNonSeparatorToken();
8282
string name = check getIdentifierTokenvalue(token);
@@ -124,10 +124,10 @@ public class Parser {
124124
if token.kind != T_DOLLAR {
125125
return getExpectedCharError(token, DOLLAR);
126126
}
127-
Location varDefinitionLocation = token.location.clone();
127+
Location varDefinitionLocation = token.location;
128128
token = check self.readNextNonSeparatorToken();
129129
string name = check getIdentifierTokenvalue(token);
130-
Location varLocation = token.location.clone();
130+
Location varLocation = token.location;
131131
token = check self.readNextNonSeparatorToken();
132132
if token.kind != T_COLON {
133133
return getExpectedCharError(token, COLON);
@@ -248,7 +248,7 @@ public class Parser {
248248
while token.kind != T_CLOSE_PARENTHESES {
249249
token = check self.readNextNonSeparatorToken();
250250
string name = check getIdentifierTokenvalue(token);
251-
Location location = token.location.clone();
251+
Location location = token.location;
252252
token = check self.readNextNonSeparatorToken();
253253
if token.kind != T_COLON {
254254
return getExpectedCharError(token, COLON);
@@ -280,7 +280,7 @@ public class Parser {
280280
}
281281
while token.kind == T_AT {
282282
token = check self.readNextNonSeparatorToken(); //consume @
283-
Location location = token.location.clone();
283+
Location location = token.location;
284284
token = check self.readNextNonSeparatorToken();
285285
string name = check getIdentifierTokenvalue(token);
286286
token = check self.peekNextNonSeparatorToken();
@@ -301,7 +301,7 @@ public class Parser {
301301
while token.kind != T_CLOSE_PARENTHESES {
302302
token = check self.readNextNonSeparatorToken();
303303
string varName = check getIdentifierTokenvalue(token);
304-
Location location = token.location.clone();
304+
Location location = token.location;
305305
token = check self.readNextNonSeparatorToken();
306306
if token.kind != T_COLON {
307307
return getExpectedCharError(token, COLON);
@@ -349,7 +349,7 @@ public class Parser {
349349
while token.kind != T_CLOSE_BRACE {
350350
token = check self.readNextNonSeparatorToken();
351351
string fieldName = check getIdentifierTokenvalue(token);
352-
Location fieldLocation = token.location.clone();
352+
Location fieldLocation = token.location;
353353
if visitedFields.indexOf(fieldName) != () {
354354
return getDuplicateFieldError(token);
355355
}

0 commit comments

Comments
 (0)