/// <inheritdoc />
        public IEnumerable <char> Process(char input)
        {
            if (this.inputPreprocessors.Count == 0)
            {
                yield return(input);

                yield break;
            }

            Queue <PreprocessedInput> processQueue = queuePool.Create();
            Queue <PreprocessedInput> outputQueue  = queuePool.Create();

            processQueue.Enqueue(input);

            foreach (var preprocessor in this.inputPreprocessors)
            {
                while (processQueue.Count > 0)
                {
                    var toProcess = processQueue.Dequeue();
                    if (toProcess.Replacement != null)
                    {
                        foreach (var toProcessChar in toProcess.Replacement)
                        {
                            outputQueue.Enqueue(preprocessor.Preprocess(toProcessChar));
                        }
                    }
                    else
                    {
                        outputQueue.Enqueue(preprocessor.Preprocess(toProcess.Value));
                    }
                }

                outputQueue = Interlocked.Exchange(ref processQueue, outputQueue);
            }

            while (processQueue.Count > 0)
            {
                var toReturn = processQueue.Dequeue();
                if (toReturn.Replacement != null)
                {
                    foreach (var letter in toReturn.Replacement)
                    {
                        yield return(letter);
                    }
                }
                else
                {
                    yield return(toReturn.Value);
                }
            }

            queuePool.Return(processQueue);
            queuePool.Return(outputQueue);
        }
Exemple #2
0
        public virtual void WriteString(string s)
        {
            var buf = SharedPool <byte> .Rent(Encoding.UTF8.GetByteCount(s));

            try
            {
                var numberOfBytes = Encoding.UTF8.GetBytes(s, 0, s.Length, buf, 0);

                WriteBinary(buf, 0, numberOfBytes);
            }
            finally
            {
                SharedPool <byte> .Return(buf);
            }
        }
        public override void WriteString(string str)
        {
            var buf = SharedPool <byte> .Rent(Encoding.UTF8.GetByteCount(str));

            try
            {
                var numberOfBytes = Encoding.UTF8.GetBytes(str, 0, str.Length, buf, 0);

                Int32ToVarInt((uint)numberOfBytes, ref PreAllocatedVarInt);
                Trans.Write(PreAllocatedVarInt.bytes, 0, PreAllocatedVarInt.count);
                Trans.Write(buf, 0, numberOfBytes);
            }
            finally
            {
                SharedPool <byte> .Return(buf);
            }
        }
Exemple #4
0
 public void Destroy(Entity e)
 {
     dict.Remove(e.UID);
     SharedPool <Entity> .Return(e);
 }