mirror of
https://github.com/GOSTSec/sgminer
synced 2025-02-05 19:44:21 +00:00
Microoptimise and remove redundant copy of strdup function in calloc_strcat.
This commit is contained in:
parent
53c9cdaf56
commit
f94cff77e6
@ -2303,13 +2303,11 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
|
|||||||
|
|
||||||
/* build JSON-RPC request */
|
/* build JSON-RPC request */
|
||||||
if (work->gbt) {
|
if (work->gbt) {
|
||||||
char *gbt_block, *varint, *header;
|
char *gbt_block, *varint;
|
||||||
unsigned char data[80];
|
unsigned char data[80];
|
||||||
|
|
||||||
flip80(data, work->data);
|
flip80(data, work->data);
|
||||||
header = bin2hex(data, 80);
|
gbt_block = bin2hex(data, 80);
|
||||||
gbt_block = calloc_strcat(header);
|
|
||||||
free(header);
|
|
||||||
|
|
||||||
if (work->gbt_txns < 0xfd) {
|
if (work->gbt_txns < 0xfd) {
|
||||||
uint8_t val = work->gbt_txns;
|
uint8_t val = work->gbt_txns;
|
||||||
|
21
util.c
21
util.c
@ -1478,27 +1478,6 @@ void dev_error(struct cgpu_info *dev, enum dev_reason reason)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calloc enough memory to fit string s, rounding up to 4 byte alignment */
|
|
||||||
void *calloc_strcat(char *s)
|
|
||||||
{
|
|
||||||
size_t len = strlen(s);
|
|
||||||
void *ptr = NULL;
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
len += 1;
|
|
||||||
if (len % 4)
|
|
||||||
len += 4 - (len % 4);
|
|
||||||
ptr = calloc(len, 1);
|
|
||||||
if (unlikely(!ptr))
|
|
||||||
quit(1, "Failed to calloc ptr in calloc_str");
|
|
||||||
|
|
||||||
sprintf(ptr, "%s", s);
|
|
||||||
out:
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Realloc an existing string to fit an extra string s, appending s to it. */
|
/* Realloc an existing string to fit an extra string s, appending s to it. */
|
||||||
void *realloc_strcat(char *ptr, char *s)
|
void *realloc_strcat(char *ptr, char *s)
|
||||||
{
|
{
|
||||||
|
1
util.h
1
util.h
@ -52,7 +52,6 @@ bool extract_sockaddr(struct pool *pool, char *url);
|
|||||||
bool auth_stratum(struct pool *pool);
|
bool auth_stratum(struct pool *pool);
|
||||||
bool initiate_stratum(struct pool *pool);
|
bool initiate_stratum(struct pool *pool);
|
||||||
void dev_error(struct cgpu_info *dev, enum dev_reason reason);
|
void dev_error(struct cgpu_info *dev, enum dev_reason reason);
|
||||||
void *calloc_strcat(char *s);
|
|
||||||
void *realloc_strcat(char *ptr, char *s);
|
void *realloc_strcat(char *ptr, char *s);
|
||||||
|
|
||||||
#endif /* __UTIL_H__ */
|
#endif /* __UTIL_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user