mndrix / golog

Prolog interpreter in Go
MIT License
374 stars 39 forks source link

Use type assertions instead of reflect. #21

Closed ericlagergren closed 8 years ago

ericlagergren commented 8 years ago

This line can be simplified down to:

if r, ok := src.(io.Reader); {
    return r, nil
}

Testing it locally, this change added a 2x speedup (4.91671ms -> 2.944214ms) for creating a NewMachine. Additionally, this drops the need to include the reflection library.

ericlagergren commented 8 years ago

Additionally, a []byte case could be added that returns bytes.NewReader(x), nil to handle []byte for no additional cost.

mndrix commented 8 years ago

Please submit pull requests for code improvements. Golog was one of my first Go projects, so there's a lot of room for similar changes. I'm glad to consider them all.