Repository: actix/actix-web
File: src/httpmessage.rs (Rust)

Code before:
            req,
            buff: Vec::with_capacity(262_144),
            limit: 262_144,
        }
    }
    
    /// Change max size of payload. By default max size is 256Kb
    pub fn limit(mut self, limit: usize) -> Self {
        self.limit = limit;
        self
    }
}

impl<T> Stream for Readlines<T>
where
    T: HttpMessage + Stream<Item = Bytes, Error = PayloadError> + 'static,
{
    type Item = String;
    type Error = ReadlinesError;
    
    fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
        match self.req.poll() {
            Ok(Async::Ready(Some(bytes))) => {
                for b in bytes.iter() {
                    if *b == '\n' as u8 {
                        self.buff.push(*b);
                        let line = str::from_utf8(&*self.buff)?.to_owned();
                        self.buff.clear();
                        return Ok(Async::Ready(Some(line)));
                    } else {
                        self.buff.push(*b);
                    }
                    if self.limit < self.buff.len() {
                        return Err(ReadlinesError::LimitOverflow);
                    }
                }
                Ok(Async::NotReady)
            },
            Ok(Async::NotReady) => Ok(Async::NotReady),
            Ok(Async::Ready(None)) => {
                if self.buff.len() == 0 {
                    return Ok(Async::Ready(None));
                }
                let line = str::from_utf8(&*self.buff)?.to_owned();
                self.buff.clear();
                return Ok(Async::Ready(Some(line)))
            },
            Err(e) => Err(ReadlinesError::from(e)),
        }
    }
}

Review comment (suggestion):
This is slooow 
Search for index then do extend_from_slice
Also you can try to use .split_to() and then extend

Code after:
    fn new(req: T) -> Self {
        Readlines {
            req,
            buff: BytesMut::with_capacity(262_144),
            limit: 262_144,
            checked_buff: true,
        }
    }
    
    /// Change max line size. By default max size is 256Kb
    pub fn limit(mut self, limit: usize) -> Self {
        self.limit = limit;
        self
    }
}

impl<T> Stream for Readlines<T>
where
    T: HttpMessage + Stream<Item = Bytes, Error = PayloadError> + 'static,
{
    type Item = String;
    type Error = ReadlinesError;
    
    fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
        let encoding = self.req.encoding()?;
        // check if there is a newline in the buffer
        if !self.checked_buff {
            let mut found: Option<usize> = None;
            for (ind, b) in self.buff.iter().enumerate() {
                if *b == '\n' as u8 {
                    found = Some(ind);
                    break;
                }
            }
            if let Some(ind) = found {
                // check if line is longer than limit
                if ind+1 > self.limit {
                    return Err(ReadlinesError::LimitOverflow);
                }
                let enc: *const Encoding = encoding as *const Encoding;
                let line = if enc == UTF_8 {
                    str::from_utf8(&self.buff.split_to(ind+1))
                        .map_err(|_| ReadlinesError::EncodingError)?
                        .to_owned()
                } else {
                    encoding
                        .decode(&self.buff.split_to(ind+1), DecoderTrap::Strict)
                        .map_err(|_| ReadlinesError::EncodingError)?
                };
                return Ok(Async::Ready(Some(line)));
            }