Commit b423fe9de81ff47b74f6d2e40cd9647e0a66d85f

Con Kolivas 2013-08-11T14:06:17

Cache the hex2bin of pool nonce1 in stratum, avoiding hex2bin on each work generation.

diff --git a/cgminer.c b/cgminer.c
index c92589b..6079257 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5612,7 +5612,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	if (unlikely(!coinbase))
 		quit(1, "Failed to calloc coinbase in gen_stratum_work");
 	memcpy(coinbase, pool->swork.cb1, pool->swork.cb1_len);
-	hex2bin(coinbase + pool->swork.cb1_len, pool->nonce1, pool->n1_len);
+	memcpy(coinbase + pool->swork.cb1_len, pool->nonce1bin, pool->n1_len);
 	hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len, work->nonce2, pool->n2size);
 	memcpy(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.cb2, pool->swork.cb2_len);
 
diff --git a/miner.h b/miner.h
index 8b1946e..f2cc84b 100644
--- a/miner.h
+++ b/miner.h
@@ -1154,6 +1154,7 @@ struct pool {
 	size_t sockbuf_size;
 	char *sockaddr_url; /* stripped url used for sockaddr */
 	char *nonce1;
+	unsigned char *nonce1bin;
 	size_t n1_len;
 	uint32_t nonce2;
 	int n2size;
diff --git a/util.c b/util.c
index 3af6125..ef05881 100644
--- a/util.c
+++ b/util.c
@@ -1718,6 +1718,11 @@ resend:
 	pool->sessionid = sessionid;
 	pool->nonce1 = nonce1;
 	pool->n1_len = strlen(nonce1) / 2;
+	free(pool->nonce1bin);
+	pool->nonce1bin = calloc(pool->n1_len, 1);
+	if (unlikely(!pool->nonce1bin))
+		quit(1, "Failed to calloc pool->nonce1bin in initiate_stratum");
+	hex2bin(pool->nonce1bin, pool->nonce1, pool->n1_len);
 	pool->n2size = n2size;
 	cg_wunlock(&pool->data_lock);