Permalink
Browse files

List -> LangList and once in init

  • Loading branch information...
1 parent 7d97277 commit 3664adb3aeca9ab6fae2c6c997fb2523860491d9 @tebeka committed Apr 5, 2013
Showing with 13 additions and 9 deletions.
  1. +2 −1 ChangeLog
  2. +9 −6 snowball.go
  3. +2 −2 snowball_test.go
View
@@ -1,5 +1,6 @@
-2013-04-05 version 0.1.3
+2013-04-05 version 0.2.0
* Fix possible memory leak
+ * List -> LangList (and done once in init)
2012-12-06 version 0.1.2
* Free memory
View
@@ -17,7 +17,7 @@ import (
import "C"
const (
- Version = "0.1.3"
+ Version = "0.2.0"
)
// Stemmer structure
@@ -71,10 +71,10 @@ func (stmr *Stemmer) Stem(word string) string {
return string(buf)
}
-// List returns the list of languages supported by snowball
-func List() []string {
- names := []string{}
+var langList []string
+// List returns the list of languages supported by snowball
+func init() {
// We don't need to free since sb_stemmer_list return pointer to static variable
cp := uintptr(unsafe.Pointer(C.sb_stemmer_list()))
size := unsafe.Sizeof(uintptr(0))
@@ -84,8 +84,11 @@ func List() []string {
if len(name) == 0 {
break
}
- names = append(names, name)
+ langList = append(langList, name)
cp += size
}
- return names
+}
+
+func LangList() []string {
+ return langList
}
View
@@ -5,14 +5,14 @@ import (
)
func TestList(t *testing.T) {
- if len(List()) == 0 {
+ if len(LangList()) == 0 {
t.Fatal("No langs")
}
}
func TestListEnglish(t *testing.T) {
found := false
- for _, v := range List() {
+ for _, v := range LangList() {
if v == "english" {
found = true
break

0 comments on commit 3664adb

Please sign in to comment.