token AST tree does not need mutex
Этот коммит содержится в:
родитель
7e9d56a900
коммит
89cf447c8d
1 изменённых файлов: 2 добавлений и 16 удалений
|
@ -1,10 +1,6 @@
|
||||||
package gherkin
|
package gherkin
|
||||||
|
|
||||||
import (
|
import "github.com/l3pp4rd/go-behat/gherkin/lexer"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/l3pp4rd/go-behat/gherkin/lexer"
|
|
||||||
)
|
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
next, prev *item
|
next, prev *item
|
||||||
|
@ -13,17 +9,13 @@ type item struct {
|
||||||
|
|
||||||
type AST struct {
|
type AST struct {
|
||||||
head, tail *item
|
head, tail *item
|
||||||
mut *sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAST() *AST {
|
func newAST() *AST {
|
||||||
return &AST{mut: &sync.Mutex{}}
|
return &AST{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AST) addTail(t *lexer.Token) *item {
|
func (l *AST) addTail(t *lexer.Token) *item {
|
||||||
l.mut.Lock()
|
|
||||||
defer l.mut.Unlock()
|
|
||||||
|
|
||||||
it := &item{next: nil, prev: l.tail, value: t}
|
it := &item{next: nil, prev: l.tail, value: t}
|
||||||
if l.head == nil {
|
if l.head == nil {
|
||||||
l.head = it
|
l.head = it
|
||||||
|
@ -35,9 +27,6 @@ func (l *AST) addTail(t *lexer.Token) *item {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AST) addBefore(t *lexer.Token, i *item) *item {
|
func (l *AST) addBefore(t *lexer.Token, i *item) *item {
|
||||||
l.mut.Lock()
|
|
||||||
defer l.mut.Unlock()
|
|
||||||
|
|
||||||
it := &item{next: i, prev: i.prev, value: t}
|
it := &item{next: i, prev: i.prev, value: t}
|
||||||
i.prev = it
|
i.prev = it
|
||||||
if it.prev == nil {
|
if it.prev == nil {
|
||||||
|
@ -47,9 +36,6 @@ func (l *AST) addBefore(t *lexer.Token, i *item) *item {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AST) addAfter(t *lexer.Token, i *item) *item {
|
func (l *AST) addAfter(t *lexer.Token, i *item) *item {
|
||||||
l.mut.Lock()
|
|
||||||
defer l.mut.Unlock()
|
|
||||||
|
|
||||||
it := &item{next: i.next, prev: i, value: t}
|
it := &item{next: i.next, prev: i, value: t}
|
||||||
i.next = it
|
i.next = it
|
||||||
if it.next == nil {
|
if it.next == nil {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче