diff options
| author | 2023-02-13 18:40:48 +0000 | |
|---|---|---|
| committer | 2023-02-13 18:40:48 +0000 | |
| commit | acc95923da555b2bf17a5638e62e533218c5840a (patch) | |
| tree | 7df5d0636137efa5b49298a8f0ced81d35767a5b /vendor/codeberg.org/gruf/go-bitutil/flag.tpl | |
| parent | [docs] move federating with gotosocial documentation into single file (#1494) (diff) | |
| download | gotosocial-acc95923da555b2bf17a5638e62e533218c5840a.tar.xz | |
[performance] processing media and scheduled jobs improvements (#1482)
* replace media workers with just runners.WorkerPool, move to state structure, use go-sched for global task scheduling
* improved code comment
* fix worker tryUntil function, update go-runners/go-sched
* make preprocess functions package public, use these where possible to stop doubled up processing
* remove separate emoji worker pool
* limit calls to time.Now() during media preprocessing
* use Processor{} to manage singular runtime of processing media
* ensure workers get started when media manager is used
* improved error setting in processing media, fix media test
* port changes from processingmedia to processing emoji
* finish code commenting
* finish code commenting and comment-out client API + federator worker pools until concurrency worker pools replaced
* linterrrrrrrrrrrrrrrr
---------
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-bitutil/flag.tpl')
| -rw-r--r-- | vendor/codeberg.org/gruf/go-bitutil/flag.tpl | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/vendor/codeberg.org/gruf/go-bitutil/flag.tpl b/vendor/codeberg.org/gruf/go-bitutil/flag.tpl index 89f881930..ac00bfa97 100644 --- a/vendor/codeberg.org/gruf/go-bitutil/flag.tpl +++ b/vendor/codeberg.org/gruf/go-bitutil/flag.tpl @@ -2,14 +2,13 @@ package bitutil import ( "strings" - - "codeberg.org/gruf/go-byteutil" + "unsafe" ) {{ range $idx, $size := . }} // Flags{{ $size.Size }} is a type-casted unsigned integer with helper -// methods for easily managing up to {{ $size.Size }} bit flags. +// methods for easily managing up to {{ $size.Size }} bit-flags. type Flags{{ $size.Size }} uint{{ $size.Size }} // Get will fetch the flag bit value at index 'bit'. @@ -54,34 +53,58 @@ func (f Flags{{ $size.Size }}) Unset{{ $idx }}() Flags{{ $size.Size }} { // String returns a human readable representation of Flags{{ $size.Size }}. func (f Flags{{ $size.Size }}) String() string { - var val bool - var buf byteutil.Buffer + var ( + i int + val bool + buf []byte + ) + + // Make a prealloc est. based on longest-possible value + const prealloc = 1+(len("false ")*{{ $size.Size }})-1+1 + buf = make([]byte, prealloc) + + buf[i] = '{' + i++ - buf.WriteByte('{') {{ range $idx := .Bits }} val = f.Get{{ $idx }}() - buf.WriteString(bool2str(val) + " ") + i += copy(buf[i:], bool2str(val)) + buf[i] = ' ' + i++ {{ end }} - buf.Truncate(1) - buf.WriteByte('}') - return buf.String() + buf[i-1] = '}' + buf = buf[:i] + + return *(*string)(unsafe.Pointer(&buf)) } // GoString returns a more verbose human readable representation of Flags{{ $size.Size }}. func (f Flags{{ $size.Size }})GoString() string { - var val bool - var buf byteutil.Buffer + var ( + i int + val bool + buf []byte + ) + + // Make a prealloc est. based on longest-possible value + const prealloc = len("bitutil.Flags{{ $size.Size }}{")+(len("{{ sub $size.Size 1 }}=false ")*{{ $size.Size }})-1+1 + buf = make([]byte, prealloc) + + i += copy(buf[i:], "bitutil.Flags{{ $size.Size }}{") - buf.WriteString("bitutil.Flags{{ $size.Size }}{") {{ range $idx := .Bits }} val = f.Get{{ $idx }}() - buf.WriteString("{{ $idx }}="+bool2str(val)+" ") + i += copy(buf[i:], "{{ $idx }}=") + i += copy(buf[i:], bool2str(val)) + buf[i] = ' ' + i++ {{ end }} - buf.Truncate(1) - buf.WriteByte('}') + + buf[i-1] = '}' + buf = buf[:i] - return buf.String() + return *(*string)(unsafe.Pointer(&buf)) } {{ end }} |
