2024-04-27 17:39:25 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
2024-04-28 12:09:47 +08:00
|
|
|
import (
|
|
|
|
|
"unsafe"
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-29 22:57:40 +08:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2024-04-28 09:55:54 +08:00
|
|
|
// Slice is the runtime representation of a slice.
|
2024-04-28 12:09:47 +08:00
|
|
|
type Slice struct {
|
2024-04-30 08:23:55 +08:00
|
|
|
data unsafe.Pointer
|
|
|
|
|
len int
|
|
|
|
|
cap int
|
2024-04-28 12:09:47 +08:00
|
|
|
}
|
2024-04-27 17:39:25 +08:00
|
|
|
|
2024-04-28 09:55:54 +08:00
|
|
|
// NilSlice returns a nil slice.
|
|
|
|
|
func NilSlice() Slice {
|
2024-04-27 17:39:25 +08:00
|
|
|
return Slice{nil, 0, 0}
|
|
|
|
|
}
|
2024-04-29 22:57:40 +08:00
|
|
|
|
2024-04-30 08:23:55 +08:00
|
|
|
// NewSlice creates a new slice.
|
|
|
|
|
func NewSlice(data unsafe.Pointer, len, cap int) Slice {
|
|
|
|
|
return Slice{data, len, cap}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SliceLen returns the length of a slice.
|
|
|
|
|
func SliceLen(s Slice) int {
|
|
|
|
|
return s.len
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 22:57:40 +08:00
|
|
|
// -----------------------------------------------------------------------------
|