~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/go/token/position.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
// associated with it, and NoPos().IsValid() is false. NoPos is always
77
77
// smaller than any other Pos value. The corresponding Position value
78
78
// for NoPos is the zero value for Position.
79
 
// 
 
79
//
80
80
const NoPos Pos = 0
81
81
 
82
82
// IsValid returns true if the position is valid.
295
295
 
296
296
// NewFileSet creates a new file set.
297
297
func NewFileSet() *FileSet {
298
 
        s := new(FileSet)
299
 
        s.base = 1 // 0 == NoPos
300
 
        return s
 
298
        return &FileSet{
 
299
                base: 1, // 0 == NoPos
 
300
        }
301
301
}
302
302
 
303
303
// Base returns the minimum base offset that must be provided to
347
347
 
348
348
// Iterate calls f for the files in the file set in the order they were added
349
349
// until f returns false.
350
 
// 
 
350
//
351
351
func (s *FileSet) Iterate(f func(*File) bool) {
352
352
        for i := 0; ; i++ {
353
353
                var file *File
367
367
}
368
368
 
369
369
func (s *FileSet) file(p Pos) *File {
 
370
        s.mutex.RLock()
370
371
        // common case: p is in last file
371
372
        if f := s.last; f != nil && f.base <= int(p) && int(p) <= f.base+f.size {
 
373
                s.mutex.RUnlock()
372
374
                return f
373
375
        }
374
376
        // p is not in last file - search all files
376
378
                f := s.files[i]
377
379
                // f.base <= int(p) by definition of searchFiles
378
380
                if int(p) <= f.base+f.size {
379
 
                        s.last = f
 
381
                        s.mutex.RUnlock()
 
382
                        s.mutex.Lock()
 
383
                        s.last = f // race is ok - s.last is only a cache
 
384
                        s.mutex.Unlock()
380
385
                        return f
381
386
                }
382
387
        }
 
388
        s.mutex.RUnlock()
383
389
        return nil
384
390
}
385
391
 
389
395
//
390
396
func (s *FileSet) File(p Pos) (f *File) {
391
397
        if p != NoPos {
392
 
                s.mutex.RLock()
393
398
                f = s.file(p)
394
 
                s.mutex.RUnlock()
395
399
        }
396
400
        return
397
401
}
399
403
// Position converts a Pos in the fileset into a general Position.
400
404
func (s *FileSet) Position(p Pos) (pos Position) {
401
405
        if p != NoPos {
402
 
                s.mutex.RLock()
403
406
                if f := s.file(p); f != nil {
404
407
                        pos = f.position(p)
405
408
                }
406
 
                s.mutex.RUnlock()
407
409
        }
408
410
        return
409
411
}