Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(966)

Delta Between Two Patch Sets: src/pkg/go/token/position.go

Issue 12837044: code review 12837044: cmd/gofmt: sort more, remove some duplicate imports (Closed)
Left Patch Set: diff -r ec64f75a7995 https://code.google.com/p/go Created 10 years, 7 months ago
Right Patch Set: diff -r ec64f75a7995 https://code.google.com/p/go Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/go/ast/import.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // TODO(gri) consider making this a separate package outside the go directory. 5 // TODO(gri) consider making this a separate package outside the go directory.
6 6
7 package token 7 package token
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 // AddLine adds the line offset for a new line. 127 // AddLine adds the line offset for a new line.
128 // The line offset must be larger than the offset for the previous line 128 // The line offset must be larger than the offset for the previous line
129 // and smaller than the file size; otherwise the line offset is ignored. 129 // and smaller than the file size; otherwise the line offset is ignored.
130 // 130 //
131 func (f *File) AddLine(offset int) { 131 func (f *File) AddLine(offset int) {
132 f.set.mutex.Lock() 132 f.set.mutex.Lock()
133 if i := len(f.lines); (i == 0 || f.lines[i-1] < offset) && offset < f.si ze { 133 if i := len(f.lines); (i == 0 || f.lines[i-1] < offset) && offset < f.si ze {
134 f.lines = append(f.lines, offset) 134 f.lines = append(f.lines, offset)
135 } 135 }
136 f.set.mutex.Unlock()
137 }
138
139 // RemoveLine removes a line by line number as reported by Position.Line.
gri 2013/09/10 20:51:05 RemoveLine is slightly misleading a name. This fu
josharian 2013/09/10 23:34:49 Agreed. I started with RemoveNewline, was unsure a
140 //
141 func (f *File) RemoveLine(line int) {
142 f.set.mutex.Lock()
143 copy(f.lines[line:], f.lines[line+1:])
144 f.lines = f.lines[:len(f.lines)-1]
136 f.set.mutex.Unlock() 145 f.set.mutex.Unlock()
137 } 146 }
138 147
139 // SetLines sets the line offsets for a file and returns true if successful. 148 // SetLines sets the line offsets for a file and returns true if successful.
140 // The line offsets are the offsets of the first character of each line; 149 // The line offsets are the offsets of the first character of each line;
141 // for instance for the content "ab\nc\n" the line offsets are {0, 3}. 150 // for instance for the content "ab\nc\n" the line offsets are {0, 3}.
142 // An empty file has an empty line offset table. 151 // An empty file has an empty line offset table.
143 // Each line offset must be larger than the offset for the previous line 152 // Each line offset must be larger than the offset for the previous line
144 // and smaller than the file size; otherwise SetLines fails and returns 153 // and smaller than the file size; otherwise SetLines fails and returns
145 // false. 154 // false.
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 h := i + (j-i)/2 // avoid overflow when computing h 441 h := i + (j-i)/2 // avoid overflow when computing h
433 // i ≤ h < j 442 // i ≤ h < j
434 if a[h] <= x { 443 if a[h] <= x {
435 i = h + 1 444 i = h + 1
436 } else { 445 } else {
437 j = h 446 j = h
438 } 447 }
439 } 448 }
440 return i - 1 449 return i - 1
441 } 450 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b