w2v-server: use memmove instead of loops in kbest
diff --git a/w2v-server.pl b/w2v-server.pl
index a83f37e..5664290 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -264,15 +264,13 @@
         if(f > worstbest) {
           for (b = 0; b < N; b++) {
             if (f > bestf[b]) {
-              for (e = N - 1; e > b; e--) {
-                bestf[e] = bestf[e - 1];
-                besti[e] = besti[e - 1];
-                bestp[e] = bestp[e - 1];
-              }
-              bestf[b] = f;
-              besti[b] = target;
-              bestp[b] = window-a;
-              break;
+							memmove(bestf + b + 1, bestf + b, (N - b -1) * sizeof(float));
+							memmove(besti + b + 1, besti + b, (N - b -1) * sizeof(long long));
+							memmove(bestp + b + 1, bestp + b, (N - b -1) * sizeof(long long));
+							bestf[b] = f;
+							besti[b] = target;
+							bestp[b] = window-a;
+							break;
             }
           }
           worstbest = bestf[N-1];
@@ -284,7 +282,7 @@
         maxmax_f = max_f;
         maxmax_target = max_target;
       }
-      for (b = 0; b < N; b++) 
+      for (b = 0; b < N; b++)
         if(bestp[b] == window-a)
           bestn[b] = bestf[b] / wpos_sum;
     } else {
@@ -404,10 +402,8 @@
 		if(dist > worstbest) {
 			for (a = 0; a < N; a++) {
 				if (dist > bestd[a]) {
-					for (d = N - 1; d > a; d--) {
-						bestd[d] = bestd[d - 1];
-						besti[d] = besti[d - 1];
-					}
+					memmove(bestd + a + 1, bestd + a, (N - a -1) * sizeof(float));
+					memmove(besti + a + 1, besti + a, (N - a -1) * sizeof(long long));
 					bestd[a] = dist;
 					besti[a] = c;
 					break;