Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
6aeaa5d3
Commit
6aeaa5d3
authored
Nov 17, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/token position: code improvements per rsc's suggestion
R=rsc CC=golang-dev
https://golang.org/cl/3183041
parent
ac966ac7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
28 deletions
+7
-28
src/pkg/go/token/position.go
src/pkg/go/token/position.go
+7
-28
No files found.
src/pkg/go/token/position.go
View file @
6aeaa5d3
...
@@ -94,19 +94,12 @@ func (p Pos) IsValid() bool {
...
@@ -94,19 +94,12 @@ func (p Pos) IsValid() bool {
func
searchFiles
(
a
[]
*
File
,
x
int
)
int
{
func
searchFiles
(
a
[]
*
File
,
x
int
)
int
{
i
:=
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
.
base
<
x
})
return
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
.
base
<=
x
})
-
1
// TODO(gri) The code below is really unfortunate. With the old
// semantics of sort.Search, it was possible to simply
// return i! Need to rethink the Search API.
if
i
==
0
||
i
<
len
(
a
)
&&
a
[
i
]
.
base
==
x
{
return
i
}
return
i
-
1
}
}
func
(
s
*
FileSet
)
file
(
p
Pos
)
*
File
{
func
(
s
*
FileSet
)
file
(
p
Pos
)
*
File
{
if
i
:=
searchFiles
(
s
.
files
,
int
(
p
));
i
<
len
(
s
.
files
)
{
if
i
:=
searchFiles
(
s
.
files
,
int
(
p
));
i
>=
0
{
return
s
.
files
[
i
]
return
s
.
files
[
i
]
}
}
return
nil
return
nil
...
@@ -259,39 +252,25 @@ func (f *File) Position(offset int) Position {
...
@@ -259,39 +252,25 @@ func (f *File) Position(offset int) Position {
func
searchUints
(
a
[]
int
,
x
int
)
int
{
func
searchUints
(
a
[]
int
,
x
int
)
int
{
i
:=
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
<
x
})
return
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
<=
x
})
-
1
// TODO(gri) The code below is really unfortunate. With the old
// semantics of sort.Search, it was possible to simply
// return i! Need to rethink the Search API.
if
i
==
0
||
i
<
len
(
a
)
&&
a
[
i
]
==
x
{
return
i
}
return
i
-
1
}
}
func
searchLineInfos
(
a
[]
lineInfo
,
x
int
)
int
{
func
searchLineInfos
(
a
[]
lineInfo
,
x
int
)
int
{
i
:=
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
.
offset
<
x
})
return
sort
.
Search
(
len
(
a
),
func
(
i
int
)
bool
{
return
a
[
i
]
.
offset
<=
x
})
-
1
// TODO(gri) The code below is really unfortunate. With the old
// semantics of sort.Search, it was possible to simply
// return i! Need to rethink the Search API.
if
i
==
0
||
i
<
len
(
a
)
&&
a
[
i
]
.
offset
==
x
{
return
i
}
return
i
-
1
}
}
// info returns the file name, line, and column number for a file offset.
// info returns the file name, line, and column number for a file offset.
func
(
f
*
File
)
info
(
offset
int
)
(
filename
string
,
line
,
column
int
)
{
func
(
f
*
File
)
info
(
offset
int
)
(
filename
string
,
line
,
column
int
)
{
filename
=
f
.
name
filename
=
f
.
name
if
i
:=
searchUints
(
f
.
lines
,
offset
);
i
<
len
(
f
.
lines
)
{
if
i
:=
searchUints
(
f
.
lines
,
offset
);
i
>=
0
{
line
,
column
=
i
+
1
,
offset
-
f
.
lines
[
i
]
+
1
line
,
column
=
i
+
1
,
offset
-
f
.
lines
[
i
]
+
1
}
}
if
i
:=
searchLineInfos
(
f
.
infos
,
offset
);
i
<
len
(
f
.
infos
)
{
if
i
:=
searchLineInfos
(
f
.
infos
,
offset
);
i
>=
0
{
alt
:=
&
f
.
infos
[
i
]
alt
:=
&
f
.
infos
[
i
]
filename
=
alt
.
filename
filename
=
alt
.
filename
if
i
:=
searchUints
(
f
.
lines
,
alt
.
offset
);
i
<
len
(
f
.
lines
)
{
if
i
:=
searchUints
(
f
.
lines
,
alt
.
offset
);
i
>=
0
{
line
+=
alt
.
line
-
i
-
1
line
+=
alt
.
line
-
i
-
1
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment